In order to make a music disk (with a menu, a scroller and something to visualize YM levels), I'm teaching myself assembly, using mostly Perihelion's and MarkeyJester’s 68K tutorials. To make sure I understand how pixels are organized in the graphic memory I made a little program that displays some text using a 8x8 pixels font stored in a PI1 file, which you can see in glorious action here: https://www.youtube.com/watch?v=DxUPrjhfeQk
The program works as expected (after countless hours of debugging with MonST indeed), the next step would be to display the characters in a 8x8 grid (to check if I got the characters alright I went for the faster way of displaying them, every 16px), but before I proceed I wanted to submit my code for review because it seems messy to me, and I wanted guidance on how to organize it better, not to mention the fact that I came up with this way of using a 8x8 font which is unlikely to be the best way, I'm sure I'm writing stupid code that wastes cycles so all help is appreciated! My end goal with this is to be able to scroll slowly an 8x8 font.
Here's the code to criticize, it compiled successfully with vasm:
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; display 8x8 blocks
;;;;;;;;;;;;;;;;;;;;;;;;;;;
section text
jsr initialise
movem.l font+2,d0-d7 ; get palette
; movem.l d0-d7,$ff8240 ; apply palette
move.w #2,-(a7) ; get physbase
trap #14 ; XBIOS
addq.l #2,a7 ; clear stack
move.l d0,screen ; store screen memory
main
move.w #37,-(sp) ; wait vbl
trap #14
addq.l #2,sp
move.l msgpointer,a0 ; pointer into the message
clr.l d0 ; clear, just to be sure
move.b (a0),d0 ; put letter ascii value in d0
cmp #0,d0 ; end of message?
bne not_end ; if not, branch
bra.w keypress
; move.l #txt,msgpointer ; reset msgpointer
; move.l msgpointer,a0
; clr.l d0 ; clear, just to be sure
; move.b (a0),d0 ; put letter ascii value in d0
not_end
move.l screen,a1
cmp #1,d0 ; new line?
bne no_new_line
addi.l #160*8,cur_y_pos
move.l #0,cur_x_pos
addi.l #1,msgpointer ; point to next character
move.l msgpointer,a3
move.b (a3),d0
no_new_line
move.l #font+34,a0 ; skip res+palette data
add.l #1,msgpointer ; point to next character
subi.l #$20,d0 ; offset so that ' ' is 0
divu.w #40,d0 ; divide by the # of columns
clr.l d1
move.w d0,d1 ; copy quotient to d1
cmpi.l #0,d1
beq rowzero ; if quotient is 0: no need to offset vertically
mulu.w #160*8,d1
add.l d1,a0
rowzero:
clr.l d2
move.l cur_x_pos,d2 ; DEBUG
add.l d2,a1
move.l cur_y_pos,d2
add.l d2,a1
clr.w d0 ; clear quotient only (w)
swap d0 ; swap with remainder
divu.w #2,d0 ; div by 2: new quotient = position of 16 px cluster
bra loophorizoffsetcheck
loophorizoffset:
add.l #8,a0
sub.w #1,d0
loophorizoffsetcheck:
cmpi.w #0,d0
bne loophorizoffset
swap d0 ; get remainder
cmpi.w #0,d0 ; if no remainder then even number of 16 px clusters
beq skipoddletter
move.l #7,d1 ; 8 pixels tall
loopoddletter:
move.b 1(a0),(a1)
move.b 3(a0),2(a1)
move.b 5(a0),4(a1)
move.b 7(a0),6(a1)
add.l #160,a0
add.l #160,a1
dbra d1,loopoddletter
bra.s skipevenletter
skipoddletter:
move.l #7,d1 ; 8 pixels tall
loopevenletter:
move.b (a0),(a1)
move.b 2(a0),2(a1)
move.b 4(a0),4(a1)
move.b 6(a0),6(a1)
add.l #160,a0
add.l #160,a1
dbra d1,loopevenletter
skipevenletter:
addi.l #8,cur_x_pos ; update cursor position
; KEYPRESS FOR DEBUG
; move.w #7,-(sp) ; wait for keypress
; trap #1 ; GEMDOS
; addq.l #2,sp
keypress:
cmp.b #$39,$fffc02 ;space pressed?
bne main
; keypress:
; move.w #7,-(sp) ; wait for keypress
; trap #1 ; GEMDOS
; addq.l #2,sp
jsr restore
clr.l -(a7)
trap #1 ; GEMDOS
include 'initlib.s'
section data
screen dc.l 0
font
incbin '0012r.PI1'
line1 dc.b "HELLO WORLD!",1
dc.b " ",1
dc.b " ",1
dc.b "LEARNING ASSEMBLY :)",1
dc.b " ",1
dc.b " ",1
dc.b "I HAS A NU TRACK:",1,1
dc.b " ",1
dc.b "CQREFREE/CQRELESS",1,1
dc.b " ",1
dc.b "ON SOUNCDCLOUD",1
dc.b " ",1
dc.b " ",1
dc.b " ",1
dc.b " ",1
dc.b " ",1
dc.b " ",1
dc.b "ALSO, cluck BITPLANES",0
even
msgpointer dc.l line1
cur_x_pos dc.l 0
cur_y_pos dc.l 0