Skip to content

Commit 0ddc9b1

Browse files
committed
Code golfing, doc fixes
1 parent 67d09e9 commit 0ddc9b1

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

MT32MSG.ASM

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ EXIT:
104104
; Filter ASCII chars to allow only 32-127
105105
;----------------------------------------------------------------------------;
106106
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
113111
EXIT:
114112
ENDM
115113

@@ -136,9 +134,9 @@ MT32 PROC NEAR
136134
JCXZ START_DISP ; jump if input length is 0 (no input)
137135
DEC CX ; remove leading character from length
138136
START_DISP:
139-
CALL STR_TO_SYSEX ; convert input string DS:[SI] to sysex data
140137
CALL MPU_RESET_UART ; reset and put in UART mode and ready
141138
JNZ MT32_EXIT ; exit if reset failed or ready timeout
139+
CALL STR_TO_SYSEX ; convert input string DS:[SI] to sysex data
142140
CALL WRITE_MPU ; write [SI] (length CX) to MPU-401
143141
JMP SHORT MPU_RESET ; reset MPU interface and return to DOS
144142

@@ -224,7 +222,7 @@ WRITE_MPU PROC
224222
JNZ WRITE_MPU_RET ; exit if DRR timeout
225223
LODSB ; load next byte
226224
OUT DX, AL ; write to DATA port
227-
STI ; restore interrupts
225+
STI ; allow interrupts between bytes
228226
IF SYSEX_DELAY GT 0
229227
MOV AX, SYSEX_DELAY ; delay for SYSEX
230228
CALL IO_DELAY_MS ; AL * ms delay
@@ -319,13 +317,13 @@ MPU_STATUS PROC
319317
; Input:
320318
; DX = MPU base (DATA) port
321319
; 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
324322
; DX = status port
325323
; Clobbers: AX
326324
;----------------------------------------------------------------------------;
327325
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)
329327

330328
;----------------------------------------------------------------------------;
331329
; MPU_POLL: Check STATUS bits with timeout
@@ -334,8 +332,9 @@ MPU_READY PROC
334332
; DX = MPU base (DATA) port
335333
; AH = status bit to poll
336334
; 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
339338
;----------------------------------------------------------------------------;
340339
MPU_POLL PROC
341340
PUSH CX ; preserve caller registers
@@ -367,29 +366,25 @@ MPU_UART ENDP
367366
; effective frequency of the counter is actually 2,386,360 Hz.
368367
;
369368
; 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
372371
;
373372
; Based on contribution by @Raffzahn (under CC BY-SA 4.0):
374373
; https://retrocomputing.stackexchange.com/a/24874/21323
375374
;
376375
; https://stanislavs.org/helppc/8253.html
377376
;----------------------------------------------------------------------------;
378-
; 8253 PIT Timer
379-
PIT_CH0 EQU 40H ; Timer Channel/Counter 0
380-
PIT_CTRL EQU 43H ; Timer Control Word
381377
IO_DELAY_MS PROC
382378
PUSH DX
383379
MOV BX, 1193 * 2 ; 1,193,180 / 1000 ms * 2 = 2,386 ticks/ms
384380
MUL BX ; DX:AX = countdown of PIT ticks to wait
385381
XCHG AX, BX ; DX:BX = countdown ticks
386382
CALL IO_WAIT_LATCH ; AX = start read
387-
MOV DI, AX ; DI = last read
388383
IO_WAIT_MS_LOOP:
384+
MOV DI, AX ; DI = last read
389385
CALL IO_WAIT_LATCH ; AX = current counter reading
390386
SUB DI, AX ; DI = # of ticks elapsed since last reading
391387
SUB BX, DI ; subtract change in ticks from countdown
392-
MOV DI, AX ; DI = save the last read
393388
SBB DX, 0 ; borrow out of high word (if necessary)
394389
JAE IO_WAIT_MS_LOOP ; loop while countdown >= 0
395390
POP DX
@@ -398,6 +393,9 @@ IO_WAIT_MS_LOOP:
398393
;----------------------------------------------------------------------------;
399394
; Latch PIT 0 and read counter to AX
400395
;----------------------------------------------------------------------------;
396+
PIT_CH0 EQU 40H ; 8253 PIT Channel/Counter 0 port
397+
PIT_CTRL EQU 43H ; 8253 PIT Control Word port
398+
401399
IO_WAIT_LATCH PROC
402400
MOV AL, 0 ; Counter 0, Latch (00b)
403401
CLI ; disable interrupts

0 commit comments

Comments
 (0)