@@ -104,12 +104,10 @@ EXIT:
104
104
; Filter ASCII chars to allow only 32-127
105
105
;----------------------------------------------------------------------------;
106
106
ASC_FILTER MACRO REG
107
- LOCAL BAD , EXIT
108
- TEST REG , 11100000B ; valid if SF = 0 and ZF = 0
109
- JS BAD ; jump if ASCII > 127
110
- JNZ EXIT ; jump if ASCII >= 32
111
- BAD:
112
- MOV REG , ' ' ; replace with space
107
+ LOCAL EXIT
108
+ CMP REG , ' ' ; is ASCII >= 32 and ASCII <= 127?
109
+ JG EXIT ; valid if so
110
+ MOV REG , ' ' ; if not, replace with space
113
111
EXIT:
114
112
ENDM
115
113
@@ -136,9 +134,9 @@ MT32 PROC NEAR
136
134
JCXZ START_DISP ; jump if input length is 0 (no input)
137
135
DEC CX ; remove leading character from length
138
136
START_DISP:
139
- CALL STR_TO_SYSEX ; convert input string DS:[SI] to sysex data
140
137
CALL MPU_RESET_UART ; reset and put in UART mode and ready
141
138
JNZ MT32_EXIT ; exit if reset failed or ready timeout
139
+ CALL STR_TO_SYSEX ; convert input string DS:[SI] to sysex data
142
140
CALL WRITE_MPU ; write [SI] (length CX) to MPU-401
143
141
JMP SHORT MPU_RESET ; reset MPU interface and return to DOS
144
142
@@ -224,7 +222,7 @@ WRITE_MPU PROC
224
222
JNZ WRITE_MPU_RET ; exit if DRR timeout
225
223
LODSB ; load next byte
226
224
OUT DX , AL ; write to DATA port
227
- STI ; restore interrupts
225
+ STI ; allow interrupts between bytes
228
226
IF SYSEX_DELAY GT 0
229
227
MOV AX , SYSEX_DELAY ; delay for SYSEX
230
228
CALL IO_DELAY_MS ; AL * ms delay
@@ -319,13 +317,13 @@ MPU_STATUS PROC
319
317
; Input:
320
318
; DX = MPU base (DATA) port
321
319
; Output:
322
- ; ZF = 1 if not ready
323
- ; ZF = 0 if ready
320
+ ; ZF = 1 if ready (okay to read/write)
321
+ ; ZF = 0 if not ready or timeout
324
322
; DX = status port
325
323
; Clobbers: AX
326
324
;----------------------------------------------------------------------------;
327
325
MPU_READY PROC
328
- MOV AH , MASK DRR ; Data Receive Ready: 40h (bit 6)
326
+ MOV AH , MASK DRR ; Data Receive Ready: 40h (bit 6)
329
327
330
328
;----------------------------------------------------------------------------;
331
329
; MPU_POLL: Check STATUS bits with timeout
@@ -334,8 +332,9 @@ MPU_READY PROC
334
332
; DX = MPU base (DATA) port
335
333
; AH = status bit to poll
336
334
; Output:
337
- ; ZF = 1 if bit set
338
- ; ZF = 0 if bit not set (timeout)
335
+ ; ZF = 1 if bit is clear (okay to read/write)
336
+ ; ZF = 0 if bit is set (timeout)
337
+ ; Clobbers: AX
339
338
;----------------------------------------------------------------------------;
340
339
MPU_POLL PROC
341
340
PUSH CX ; preserve caller registers
@@ -367,29 +366,25 @@ MPU_UART ENDP
367
366
; effective frequency of the counter is actually 2,386,360 Hz.
368
367
;
369
368
; Input:
370
- ; AX = wait in number of ms (clobbered)
371
- ; Clobbers: BX, DI
369
+ ; AX = wait in number of ms
370
+ ; Clobbers: AX, BX, DI
372
371
;
373
372
; Based on contribution by @Raffzahn (under CC BY-SA 4.0):
374
373
; https://retrocomputing.stackexchange.com/a/24874/21323
375
374
;
376
375
; https://stanislavs.org/helppc/8253.html
377
376
;----------------------------------------------------------------------------;
378
- ; 8253 PIT Timer
379
- PIT_CH0 EQU 40H ; Timer Channel/Counter 0
380
- PIT_CTRL EQU 43H ; Timer Control Word
381
377
IO_DELAY_MS PROC
382
378
PUSH DX
383
379
MOV BX , 1193 * 2 ; 1,193,180 / 1000 ms * 2 = 2,386 ticks/ms
384
380
MUL BX ; DX:AX = countdown of PIT ticks to wait
385
381
XCHG AX , BX ; DX:BX = countdown ticks
386
382
CALL IO_WAIT_LATCH ; AX = start read
387
- MOV DI , AX ; DI = last read
388
383
IO_WAIT_MS_LOOP:
384
+ MOV DI , AX ; DI = last read
389
385
CALL IO_WAIT_LATCH ; AX = current counter reading
390
386
SUB DI , AX ; DI = # of ticks elapsed since last reading
391
387
SUB BX , DI ; subtract change in ticks from countdown
392
- MOV DI , AX ; DI = save the last read
393
388
SBB DX , 0 ; borrow out of high word (if necessary)
394
389
JAE IO_WAIT_MS_LOOP ; loop while countdown >= 0
395
390
POP DX
@@ -398,6 +393,9 @@ IO_WAIT_MS_LOOP:
398
393
;----------------------------------------------------------------------------;
399
394
; Latch PIT 0 and read counter to AX
400
395
;----------------------------------------------------------------------------;
396
+ PIT_CH0 EQU 40H ; 8253 PIT Channel/Counter 0 port
397
+ PIT_CTRL EQU 43H ; 8253 PIT Control Word port
398
+
401
399
IO_WAIT_LATCH PROC
402
400
MOV AL , 0 ; Counter 0, Latch (00b)
403
401
CLI ; disable interrupts
0 commit comments