-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug.z80
133 lines (109 loc) · 2.9 KB
/
debug.z80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
;; debug.asm - Enable/Disable debug-mode
;;
;; This uses the custom BIOS function we've added to the BIOS, which was never
;; present in real CP/M. Consider it a hook into the emulator.
;;
;; Debug mode, once enabled, shows a summary of syscalls made and their
;; results. It is best to use the logfile, but this can be enabled/disabled
;; at runtime which makes it nicer.
;;
FCB1: EQU 0x5C
BDOS_ENTRY_POINT: EQU 5
BDOS_OUTPUT_STRING: EQU 9
;;
;; CP/M programs start at 0x100.
;;
ORG 100H
;; Test that we're running under cpmulator by calling the
;; "is cpmulator" function.
ld HL, 0x0000
ld a, 31
out (0xff), a
;; We expect SKX to appear in registers HLA
CP 'X'
jr nz, not_cpmulator
LD A, H
CP 'S'
jr nz, not_cpmulator
LD A, L
CP 'K'
jr nz, not_cpmulator
;; The FCB will be populated with the number/first argument,
;; if the first character of that region is a space-character
;; then we've got nothing specified
ld a, (FCB1 + 1)
cp 0x20 ; 0x20 = 32 == SPACE
jp z, show_value ; Got a space, just show the value.
;; Otherwise we set
cp '1'
jr z, set_debug
cp '0'
jr z, unset_debug
jr unknown_argument
set_debug:
ld c, 0x01
jr set_debug_middle
unset_debug:
ld c, 0x00
set_debug_middle:
ld HL, 0x06
ld a, 31
out (0xff), a
;; fall-through to show the value
;; get the value of the flag
show_value:
ld c, 0xff
ld HL, 0x06
ld a, 31
out (0xff), a
ld a,c
cp 0x00
jr z,show_debug_off
cp 0x01
jr z, show_debug_on
;; unknown value
LD DE, MODE_UNKNOWN
LD C, BDOS_OUTPUT_STRING
call BDOS_ENTRY_POINT
;; fall-through
;; Exit
exit:
LD C,0x00
CALL BDOS_ENTRY_POINT
show_debug_off:
LD DE, MODE_OFF
LD C, BDOS_OUTPUT_STRING
call BDOS_ENTRY_POINT
jr exit
show_debug_on:
LD DE, MODE_ON
LD C, BDOS_OUTPUT_STRING
call BDOS_ENTRY_POINT
jr exit
;;
;; Error Routines
;;
unknown_argument:
LD DE, WRONG_ARGUMENT
LD C, BDOS_OUTPUT_STRING
call BDOS_ENTRY_POINT
jr exit
not_cpmulator:
LD DE, WRONG_EMULATOR
LD C, BDOS_OUTPUT_STRING
call BDOS_ENTRY_POINT
jr exit
;;
;; Text output strings.
;;
WRONG_ARGUMENT:
db "Usage: DEBUG [0|1]", 0x0a, 0x0d, "$"
WRONG_EMULATOR:
db "This binary is not running under cpmulator, aborting.", 0x0a, 0x0d, "$"
MODE_ON:
db "debug mode is on.", 0x0a, 0x0d, "$"
MODE_OFF:
db "debug mode is off.", 0x0a, 0x0d, "$"
MODE_UNKNOWN:
db "Failed to determine the state of debug mode.", 0x0a, 0x0d, "$"
END