📄 misc.mod
字号:
; : B is unaffected
; : Carry Clear
; : IF NOT FOUND: X is unaffected
; : B holds error code (errNotFound)
; : Carry Set
?SearchTable ldb B_,y ;get size of entries in B
ldx X_,y ;get actual X value
brclr CCR_,y,C.,?SearchTable.Byte ;go to the byte search part
?SearchTable.Loop ldd ,x ;get table value
beq ?SearchTable.Fail ;end-of-table, get out
cmpd Y_,y ;compare with word target
beq ?SearchTable.Found ;if equal, we found it!
ldb B_,y ;reload B with size of entries
abx ;point to next entry
bra ?SearchTable.Loop ;..and try again
?SearchTable.Found stx X_,y ;save return result
; clc ;not really needed after BEQ true
rts
?SearchTable.Fail ldb #errNotFound
sec
rts
?SearchTable.Byte lda ,x ;get table value
beq ?SearchTable.Fail ;end-of-table, get out
cmpa Y_+1,y ;compare with byte target
beq ?SearchTable.Found ;if equal, we found it!
abx ;point to next entry
bra ?SearchTable.Byte ;..and try again
; Purpose: Convert an A/D reading (based on 5Volt Vrh-Vrl) to an ASCII
; : string with the equivalent decimal number (10digits)
; Input : X points to beginning of output buffer
; : A holds A/D reading
; Output : Buffer pointed by X is filled with result
; : Carry Clear
; Note(s): No registers are affected
?ConvertAD ldx X_,y ;get actual X value
lda A_,y ;get actual A value
pshx
ldb #9 ;number of digits
pshb ;temporary byte for counter
tsy ;point to new stack frame
ldb #5 ;Scale to 5Volts
?Convert.Loop mul
adda #'0'
sta 1,x
inx
tba
ldb #10
dec ,y
bne ?Convert.Loop
ins ;kill temp (faster than PULB)
pulx
lda 1,x
ldb #'.'
std ,x
clc ;never an error from here
rts
; Routine: KickCOP
; Purpose: Kick the COP timer (Call this to prevent COP timeout resets)
; Input : None
; Output : None
; Note(s): Call either way: "OS fKickCOP" or "JSR KickCOP" (faster)
KickCOP equ *
#ifdef NOINTS
pshd ;save registers to be used
tpa ;keep copy of CCR
sei ;no IRQs during sequence
#else
pshb ;save registers to be used
#endif
ldb #$55
stb COPRST
comb
stb COPRST
#ifdef NOINTS
tap ;restore CCR (re-enable IRQs?)
puld ;restore used registers
#else
pulb ;restore used registers
#endif
clc ;never an error from here
rts
; Routine: HexToASCII
; Purpose: Convert a hex number in lower A to ASCII equivalent in D
; Input : A holds binary number (higher nibble is ignored)
; Output : D holds ASCII equivalent of number
?HexToASCII lda A_,y
anda #$0F ;kill higher nibble just in case
daa ;convert to BCD
tab ;make a copy in B
lsra:4 ;transfer A to lower half
andb #$0F ;clear upper half of B
addd #'00' ;finally, convert to ASCII
sta A_,y ;save result for caller
stb B_,y
?HexToASCII.Exit clc ;never an error from this routine
rts
; Routine: ReverseByte
; Purpose: Reverse a byte's bit order from MSB to LSB or back
; Input : A=byte whose bit order to change
; Output : A=byte with bit order changed
?ReverseByte ldb #8 ;number of bits
clra ;start with zero RegA
?ReverseByte.Loop lsr A_,y ;get right-most bit in Carry
rola ;get Carry in right-most RegA bit
decb ;one less bit to process
bne ?ReverseByte.Loop ;repeat for all bits
sta A_,y ;save result
clc ;never an error from here
rts
; Routine: GetBootMode
; Purpose: Reverse a byte's bit order from MSB to LSB or back
; Input : None
; Output : A=byte with bits 1-0 indicating boot mode as follows:
; %00=Single-Chip, %01=Expanded, %10=Bootstrap, %11=SpecialTest
; : X -> string with ASCIZ message indicating mode
?GetBootMode lda HPRIO ;Get current HPRIO contents
anda #%01100000 ;Mask off unwanted bits
lsra:5 ;Move mode bits to lsb
sta A_,y ;save result
beq ?GetBootMode.00
cmpa #%01
beq ?GetBootMode.01
cmpa #%10
beq ?GetBootMode.10
ldx #?BootMsg.11
bra ?GetBootMode.Exit
?GetBootMode.10 ldx #?BootMsg.10
bra ?GetBootMode.Exit
?GetBootMode.01 ldx #?BootMsg.01
bra ?GetBootMode.Exit
?GetBootMode.00 ldx #?BootMsg.00
?GetBootMode.Exit stx X_,Y
clc ;never an error from here
rts
?BootMsg.00 fcs 'Single-Chip'
?BootMsg.01 fcs 'Expanded'
?BootMsg.10 fcs 'Bootstrap'
?BootMsg.11 fcs 'Special Test'
; Routine: IncBCD
; Purpose: Increment a BCD number
; Input : A=BCD number to increment
; Output : A=incremented BCD number
?IncBCD lda A_,y ;Get value to increment
adda #1 ;increment it (Do NOT use INCA
daa ;or DAA won't work)
sta A_,y ;save it
clc ;never an error from here
rts
; Routine: DecBCD
; Purpose: Decrement a BCD number
; Input : A=BCD number to decrement
; Output : A=decremented BCD number
?DecBCD lda A_,y ;Get value to decrement
suba #1 ;decrement it (Do NOT use DECA
daa ;or DAA won't work)
sta A_,y ;save it
clc ;never an error from here
rts
; Routine: HexToBin
; Purpose: Convert a hex string to binary number
; Input : D=hex string
; Output : A=binary equivalent
?HexToBin lda A_,Y
bsr ?Upcase
bsr ?HexToBin.Digit
lsla:4
sta A_,Y
lda B_,Y
bsr ?Upcase
bsr ?HexToBin.Digit
ora A_,Y
sta A_,Y
clc
rts
?HexToBin.Error sec
rts
?HexToBin.Digit cmpa #'0'
blo ?HexToBin.Error
cmpa #'F'
bhi ?HexToBin.Error
cmpa #'9'
bls ?HexToBin.Number
cmpa #'A'
blo ?HexToBin.Error
suba #'A'-10-'0'
?HexToBin.Number suba #'0'
rts
#PAGE
*********************************************************************
* GENERAL-PURPOSE ROUTINES *
*********************************************************************
; Purpose: Convert a binary number to ASCII equivalent
; Input : B holds binary number
; Output : B holds ASCII equivalent
ToDigit addb #'0' ;convert to ASCII
cmpb #'9'
bls ?ToDigit.Exit
addb #'A'-'0'-10 ;adjust for appropriate letter
?ToDigit.Exit clc
rts
?Upcase cmpa #'a'
blo ?Upcase.Exit
cmpa #'z'
bhi ?Upcase.Exit
suba #'a'-'A'
?Upcase.Exit rts
#ifmain
#include DISPATCH.MOD
#endif
#ROM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -