-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPMIO.MAC
119 lines (91 loc) · 2.98 KB
/
CPMIO.MAC
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
; Register preserving wrapper functions for safe and consistent access to BDOS.
; Dogma: Only registers A & HL are corrupted
; register A is used for single byte arguements and return vlaues
; register HL is used to access all other arguements and return values via the descirbed memory structures
.8080 ; accept only 8080 opcodes
NAME ('CPMIO') ; set the module name (overrides title)
; *only the first 6 characters are significant*
TITLE CP/M I/O subroutines 04 October
INCLUDE EXTEND.MAC ; macros to extend the 8080's limited instruction set
CSEG ; code segment relocatable code
; Return control to the CP/M operating system at the CCP level.
RESET:: PUSHA ; preserve registers
MVI C, RESETF##
CALL BDOS## ; NB the double hash indicates to M80 an external name
POPA ; restore registers
RET
; Get ASCII character from console device CON in register A (with echo)
; Graphic characters, along with carriage return, line- feed, and back space (CTRL-H) are echoed to the console.
; Tab characters, CTRL-I, move the cursor to the next tab stop.
; A check is made for start/stop scroll, CTRL-S, and start/stop printer echo, CTRL-P.
; The FDOS does not return to the calling program until a character has been typed, thus suspending execution if a character is not ready.
GCHR:: PUSHA
MVI C, RCONF##
CALL BDOS##
POPA
RET
; Print ASCII character in register A to console device CON:
; As in GCHR, tabs are expanded and checks are made for start/stop scroll and printer echo.
PCHR:: PUSHA
MVI C, WCONF##
MOV E, A
CALL BDOS## ; destroys HL
POPA
RET
; Print the hexadecimal value of register A to CON:
PHEX:: PUSHA
MOV B, A ; copy A then process high nybble
RRC ; 8080 has no shift instruction
RRC ; Only rotate instructions.
RRC ; So to shift high nybble right 4 places,
RRC ; rotate right four places and then
ANI 0FH ; mask the low 4 bits
ADI '0' ; convert to ASCII
CPI ':' ; ASCII 9 or less?
JC HIDIGIT
ADI 7 ; convert to hex characters A..F
HIDIGIT: CALL PCHR ; print the high nybble
MOV A, B ; restore A then process low nybble
ANI 0FH ; mask the low nybble 4 bits
ADI '0' ; convert to ASCII
CPI ':' ; ASCII 9 or less?
JC LODIGIT
ADI 7 ; convert to hex characters A..F
LODIGIT: CALL PCHR ; print the low nybble
POPA
RET
; Print the binary value of register A to CON:
PBIN:: PUSHA
MVI D, 8
BDIGIT: RAL
JNC BZERO
MVI E, '1'
JMP BCHR
BZERO: MVI E, '0'
BCHR: MVI C, WCONF##
PUSH PSW
CALL BDOS##
POP PSW
DCR D
JNZ BDIGIT
POPA
RET
; Print the binary value of register HL to CON:
PDBIN:: PUSHA
MOV A, H
CALL PBIN
MOV A, L
CALL PBIN
POPA
RET
; print the zero terminated string HL to CON:
PZSTR:: PUSHA
PZLOOP: MOV A, M
CPI 0
JZ PZEND
CALL PCHR
INX HL
JMP PZLOOP
PZEND: POPA
RET
END