2 Likes
#assembler
2 Likes
4 Likes
1 Shares
6502/6510 c64 assembler - fill2.asm
Version 2 with additional routines to clear the screen, end the program when runstop key (ESC) is pressed and colors for background, borders and text. original: jimjim
// fill2.asm
// fill the screen with the pressed key char
// used Assembler: Kick Assembler 5.24
////////////////////////////////////////////////
.var getin=$ffe4 // GETIN kernal routine which checks for input
// 0 when no key is pressed
// see www.c64-wiki.de/wiki/KERNAL
// for example
.var screenmem=$0400 // a var for screen memory start (dec 1024)
.var cls=$e544 // kernal routine to clear the screen
.var black=$0 // color code for black
.var white=$1 // color code for white
.var bgcolor=$d020 // address for the screen background color
.var bordcolor=$d021 // address for screen border color
.var txtcolor=$286 // address for text color
BasicUpstart2(start) //KickAss function for BASIC start line, very helpful
*=$2000 // entrypoint for our asm routines, decimal 8192
// BASIC line will be 10 SYS 8192 ( = $2000 )
start: // the label BasicUpstart2 uses above.
// the entrypoint of our asm routine
lda #black // load color - with hash because we load a number, not an address
sta bordcolor // store black in the border color address
lda #black // load color
sta bgcolor // store black in background color address
lda #white // load color
sta txtcolor // store white in text color
jsr cls // clear the screen with cls kernal routine
ldx #$00 // clear x, offset
introloop:
lda introtext,x // load text address in x
beq charloop // branch to charloop if text end has been reached (byte 0)
sta screenmem,x // store accu
inx // next char
jmp introloop // loop
charloop: // another label for the loop below
jsr getin // "jump to subroutine" GETIN in kernal
cmp #$00 // compare memory and accumulator
beq charloop // if cmp returns 0 then go back to loop start
cmp #$103 // cmp if Run/Stop is pressed (103), which is ESC on a PC
beq quit // if Run/Stop was pressed, go to quit (end program)
sec // set the carry flag, otherwise we dont get the char we pressed but the one below (H will become G etc.)
sbc #$40 // we have the ASCII value in our accumulator and need to convert it to the screen code value
// To do that, we sbc (SuBtract from accu with Carry) dec64 aka $40
ldx #$00 // load the x register with zero
screenloop:
sta screenmem,x // store the accu in screenmem with an offset of x. Works like a for/next loop
sta screenmem+255,x // part 2 of the screen which is 1000 chars wide and we can only store 255 in a register :)
sta screenmem+510,x // part 3 of the screen
sta screenmem+744,x // part 4 of the screen <- don't add 255 here, just use 744 (999-255) instead
inx // increase x
bne screenloop // branch to screenloop until zero. aka loop ;)
jmp charloop // jump to the input routine for the next char
quit: // another label, not used here, just a marker for 'program ends here'
jsr cls // clear the screen
rts // return to BASIC
introtext: // a label to let the program know where the text is stored
.text "press key to display, runstop to quit"
.byte 0
tools used:
* VS Code 1.66.2
* Vice GTK3, v3.6.1
* Kick Assembler 5.24
* C64Debugger (C64 65XE NES Debugger v0.64.58.6.win32)
6502/6510 c64 assembler - fillscreen.asm
this waits for input and fills the whole screen with a char of the pressed key. comments ftw. so I will know tomorrow what I wrote yesterday and which assembler to use to assemble it. Kick Assembler is nice, it offers useful helpers like an automatic routine BasicUpstart2() to generate the BASIC starter which starts the assembler routine (it's a jmp to the used label as usual but you don't have to fiddle out the hex address). original: jimjim
```
// fill.asm
// fill the screen with the pressed key char
// used Assembler: Kick Assembler 5.24
////////////////////////////////////////////////
.var getin=$ffe4 // GETIN kernal routine which checks for input
// 0 when no key is pressed
// see www.c64-wiki.de/wiki/KERNAL
// for example
.var screenmem=$0400 // a var for screen memory start (dec 1024)
BasicUpstart2(start) //KickAss function for BASIC start line, very helpful
*=$2000 // entrypoint for our asm routines, decimal 8192
// BASIC line will be 10 SYS 8192 ( = $2000 )
start: // the label BasicUpstart2 uses above.
// the entrypoint of our asm routine
charloop: // another label for the loop below
jsr getin // "jump to subroutine" GETIN in kernal
cmp #$00 // compare memory and accumulator
beq charloop // if cmp returns 0 then go back to loop start
sec // set the carry flag, otherwise we dont get the char we pressed but the one below (H will become G etc.)
sbc #$40 // we have the ASCII value in our accumulator and need to convert it to the screen code value
// To do that, we sbc (SuBtract from accu with Carry) dec64 aka $40
ldx #$00 // load the x register with zero
screenloop:
sta screenmem,x // store the accu in screenmem with an offset of x. Works like a for/next loop
sta screenmem+255,x // part 2 of the screen which is 1000 chars wide and we can only store 255 in a register :)
sta screenmem+510,x // part 3 of the screen
sta screenmem+744,x // part 4 of the screen <- don't add 255 here, just use 744 (999-255) instead
inx // increase x
bne screenloop // branch to screenloop until zero. aka loop ;)
jmp charloop // jump to the input routine for the next char
quit: // another label, not used here, just a marker for 'program ends here'
rts // return to BASIC
```
tools used:
- VS Code 1.66.2
- Vice GTK3, v3.6.1
- Kick Assembler 5.24
- C64Debugger (C64 65XE NES Debugger v0.64.58.6.win32)
One person like that
Writing a #SNES #assembler compiler/disassembler - Day 1 http://blogs.perl.org/users/sylvain_colinet/2021/12/writing-a-snes-assembler-compilerdisassembler---day-1.html #Perl #Programming