Last active
January 8, 2023 05:47
-
-
Save cbmeeks/7e499c432f1231233dabce1ef1a080ce to your computer and use it in GitHub Desktop.
Simple integer to hex print in 6502 assembly language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is for the Commodore 64 and requires KickAssembler | |
// Written by Cecil Meeks (cbmeeks) in 2023 | |
// NOTE, this prints whatever is in A to the screen. So load A first. | |
// First, create a simple macro: | |
.macro DebugText_A_Hex(X, Y) { | |
sta ModA + 1 // save A below | |
stx ModX + 1 // save X below | |
sty ModY + 1 // save Y below | |
pha // push A to stack | |
and #%00001111 // grab lower nybble | |
tay // move A to Y | |
lda DEBUG.HEX, y // lookup character from table | |
sta $0400 + (Y * 40) + X + 1 // plot to screen at coordinates + 1 | |
pla // pull A off stack | |
and #%11110000 // grab upper nybble | |
lsr | |
lsr | |
lsr | |
lsr // move to lower nybble | |
tay // move A to Y | |
lda DEBUG.HEX, y // lookup character from table | |
sta $0400 + (Y * 40) + X // plot to screen at coordinates | |
// restore everything | |
ModA: lda #$00 | |
ModX: ldx #$00 | |
ModY: ldy #$00 | |
} | |
// table used (resides in a class) | |
DEBUG: { | |
HEX: { | |
.byte $30, $31, $32, $33, $34, $35, $36, $37, $38, $39 // 0-9 | |
.byte $01, $02, $03, $04, $05, $06 // A-F | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment