woz64/libs/print.asm

204 lines
5.6 KiB
NASM
Raw Permalink Normal View History

2020-01-12 08:10:01 +00:00
#importonce
#import "math.asm"
2020-01-20 07:32:37 +00:00
#import "../devices/video.asm"
2020-01-19 06:48:59 +00:00
#import "../core/module.asm"
2020-01-12 08:10:01 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// MACROS //////////////////////////////////////////
// ========================================================
2020-01-12 08:10:01 +00:00
.macro PrintLine(stringAddr) {
2020-01-13 01:24:10 +00:00
lda #<stringAddr // Low byte
ldx #>stringAddr // High byte
jsr Print.printLine
2020-01-12 08:10:01 +00:00
}
.macro PrintChar() {
2020-01-13 01:24:10 +00:00
jsr Print.printPetChar
2020-01-12 08:10:01 +00:00
}
.macro PrintNewLine() {
2020-01-20 07:32:37 +00:00
jsr Video.screenNewLine
2020-01-12 08:10:01 +00:00
}
.filenamespace Print
2020-01-13 00:52:10 +00:00
* = * "Print Lib"
// ========================================================
// ////// METHODS /////////////////////////////////////////
// ========================================================
// --------------------------------------------------------
// init -
// Module Init.
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
init: {
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// toDebug -
// Print debug info.
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
toDebug: {
2020-01-13 00:52:10 +00:00
ModuleToDebug(module_type, module_name, version)
2020-01-12 08:10:01 +00:00
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// printPetChar -
2020-01-20 07:32:37 +00:00
// Convert a Char from PET ASCII and print it out on Video
2020-01-13 00:52:10 +00:00
//
// Parameters:
// A = PET ASCII char to print
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
printPetChar: {
2020-01-13 07:33:13 +00:00
phr
2020-01-20 07:32:37 +00:00
jsr Print.petCharToVideoChar
jsr Video.sendChar
2020-01-13 07:33:13 +00:00
plr
2020-01-12 08:10:01 +00:00
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// printLine -
2020-01-20 07:32:37 +00:00
// Print a Null terminated VIDEO ASCII string to screen.
2020-01-12 08:10:01 +00:00
//
2020-01-13 00:52:10 +00:00
// Parameters:
// A = low byte string address
// X = low byte string address
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
printLine: {
2020-01-13 01:24:10 +00:00
ldy #$00
2020-01-19 06:48:59 +00:00
sta MemMap.PRINT.TempStringPointer
stx MemMap.PRINT.TempStringPointer+1
2020-01-12 08:10:01 +00:00
printLoop:
2020-01-19 06:48:59 +00:00
lda (MemMap.PRINT.TempStringPointer), y
2020-01-13 01:24:10 +00:00
cmp #0
beq exit
2020-01-20 07:32:37 +00:00
jsr Video.sendChar
2020-01-13 01:24:10 +00:00
jmp printLoop
2020-01-12 08:10:01 +00:00
exit:
2020-01-13 01:24:10 +00:00
rts
2020-01-12 08:10:01 +00:00
}
2023-07-03 04:10:00 +00:00
// Hexadecimal lookup table
hexTable: .text "0123456789ABCDEF"
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// byteToHex -
// Convert a byte to an HEX value
//
// Parameters:
// Y = Byte to Convert
2020-01-12 08:10:01 +00:00
//
2020-01-13 00:52:10 +00:00
// Result:
// A = msn ascii char result
// X = lns ascii char result
// --------------------------------------------------------
2023-07-03 04:10:00 +00:00
byteToHex: {
tay // Save the original byte in Y
and #$0F // Mask the lower 4 bits (nibble)
tax // Transfer the lower nibble to X register
lda hexTable, x // Load the ASCII value of the least significant hex digit
tya // Restore the original byte from Y
lsr // Shift the upper 4 bits (nibble) to the right
lsr
lsr
lsr
tax // Transfer the upper nibble to X register
pha // Push the ASCII value of the least significant hex digit to stack
lda hexTable, x // Load the ASCII value of the most significant hex digit
tax // Transfer the ASCII value of the most significant hex digit to X
pla // Pop the ASCII value of the least significant hex digit from stack to A
rts // Return from the function // Return from the function
2020-01-12 08:10:01 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
// petCharToVideoChar -
// Convert a PET ASCII Char to a VIDEO ASCII Char
2020-01-12 08:10:01 +00:00
//
2020-01-13 00:52:10 +00:00
// Parameters:
// A = PET ASCII Byte to Convert
//
// Result:
2020-01-20 07:32:37 +00:00
// A = Converted ASCII VIDEO Char
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
2020-01-20 07:32:37 +00:00
petCharToVideoChar: {
2020-01-12 08:10:01 +00:00
// $00-$1F
cmp #$1f
bcs !+
sec
adc #128
jmp convDone
// $20-$3F
!:
cmp #$3f
bcs !+
jmp convDone
// $40-$5F
!:
cmp #$5f
bcs !+
sec
sbc #$40
jmp convDone
// $60-$7F
!:
cmp #$7F
bcs !+
sec
sbc #32
jmp convDone
// $80-$9F
!:
cmp #$9F
bcs !+
sec
adc #64
jmp convDone
// $A0-$BF
!:
cmp #$BF
bcs !+
sec
sbc #64
jmp convDone
// $C0-$DF
// $E0-$FE
!:
cmp #$FE
bcs !+
sec
sbc #128
jmp convDone
// $FF
!:
lda $5E
convDone:
rts
}
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// DATA ////////////////////////////////////////////
// ========================================================
2020-01-12 08:10:01 +00:00
* = * "Print Lib Data"
2020-01-13 01:24:10 +00:00
module_type: .byte Module.TYPES.LIB
version: .byte 1, 0, 0
2020-01-13 00:52:10 +00:00
.encoding "screencode_mixed"
2020-01-12 08:10:01 +00:00
module_name:
2020-01-13 01:24:10 +00:00
.text "print"
.byte 0
2020-01-12 08:10:01 +00:00
2020-01-20 07:38:20 +00:00
#import "../hardware/mem_map.asm"
2020-01-12 08:10:01 +00:00