Page 1 of 2

Assembly: How to save RAM, and how to print RAM to the screen

Posted: Thu Dec 23, 2021 5:22 pm
by rje

I have a two-parter question.

1. How might I dump a screen of PETSCII to a binary file?

I print splash screens and similar, storing the content char arrays in C, or sometimes programmatically printing it out.  I’d like to store that data in a binary.  I’m not sure how to do that from the X16.

 

2. Then of course I want to write a short asm that prints that to the screen.  The only way I think of this is by using FFD2, but maybe there are better ways?  Also note problems with my code here!

entry:

lda clear-screen-code

jsr $ffd2

ldx #0

printloop:

lda $8000,x

cmp $ff  or whatever makes sense here

beq done

jsr $ffd2 

inx    Uh oh that won’t work because x is only 8 bits.... can I increment A indirectly?

jmp printloop.  But I know there’s a better way to do that.

done:

rts

 


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Thu Dec 23, 2021 6:36 pm
by TomXP411

The general solution is to

1. read up on file I/O using KERNAL calls  I’ll dig out my ASM directory program for you. It might also be in the file section here  

2. use a 16 bit counter. This involves doing the usual INC and checking the carry flag. 

 

This opens a file for reading. I believe to write to the file, you'd use CHKOUT at the end. 

    lda #filename_len-filename

    ldx #<filename

    ldy #>filename

    jsr SETNAM

    

    lda #FILE_CHANNEL

    ldx #DEVICE_NUMBER

    ldy #SECONDARY_ADDRSS_DIR

    jsr SETLFS

    jsr OPEN

    ldx #FILE_CHANNEL

    jsr CHKIN

After that, calls to CHRIN or BASIN would read from the disk channel. To change back to the screen

JSR CLRCHN

I've attached my directory reader ASM and my labels for your reference. 
labels.asm
dir.asm

Assembly: How to save RAM, and how to print RAM to the screen

Posted: Thu Dec 23, 2021 7:09 pm
by Greg King


On 12/23/2021 at 12:22 PM, rje said:




I have a two-parter question.



1. How might I dump a screen of PETSCII to a binary file?

    I print splash screens and similar, storing the content char arrays in C, or sometimes programmatically printing them out.  I’d like to store that data in a binary.  I’m not sure how to do that from the X16.



2. Then of course I want to write a short asm that prints that to the screen.  The only way I think of this is by using $FFD2, but maybe there are better ways?  Also note problems with my code here!



entry:

lda clear-screen-code

jsr $ffd2

ldx #0

printloop:

lda $8000,x

cmp $ff;  or whatever makes sense here

beq done

jsr $ffd2

inx   ; Uh oh, that won’t work because x is only 8 bits. Can I increment A indirectly?

jmp printloop.  ; But, I know there’s a better way to do that.

done:

rts



Answer #2:

You must read the text through an indirect pointer.  Use two nested loops.  Increment the index in the inner loop.  Increment the high byte of the pointer in the outer loop.

entry:

    lda #clear-screen-code

    jsr CHROUT

    lda #<$8000

    ldx #>$8000

    sta r0

    stx r0+1

    ldy #0

loop:

    lda (r0),y

    beq done

    jsr CHROUT

    iny

    bne loop

    inc r0+1

    bra loop

done:

    rts


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Thu Dec 23, 2021 8:00 pm
by Greg King

What kind of data do you want to put in a file?


  1. Some text before it's printed.


  2. Or, something that you programmatically formatted and printed onto the display screen?


(If it's the second kind, then you will have screen-codes in VRAM, not PetSCII in main RAM.)


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Thu Dec 23, 2021 11:34 pm
by ZeroByte

Does VSAVE exist? If so just do that and do VLOAD to put it on the screen.

In assembly, VLOAD is:

Usual call to SETNAM/ and usual call SETLFS with A=0, X = 8 and Y=0

Then call LOAD with A=2|3 and XY = VRAM address. (A = bank+2)

(edited to fix erroneous info)


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Thu Dec 23, 2021 11:39 pm
by ZeroByte

If no VSAVE then copy the screen tile map data from 00000 to 03FFF into main memory from 5000

Then do a normal call to save giving 5000 to 8FFF as the area to save.

SAVE doesn’t work right for HiRAM yet (at least not in the Kernal) which is why I suggested Main memory.


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Fri Dec 24, 2021 3:53 am
by Greg King


On 12/23/2021 at 6:34 PM, ZeroByte said:




Does VSAVE exist? If so just do that and do VLOAD to put it on the screen.



In assembly, VLOAD is:



Usual call to SETNAM.

Call SETLFS with A=2 or 3 (VRAM bank + 2), X = 8, and Y=0.

Then call LOAD with A=0 and XY = VRAM address.



That's BASIC's way of doing it.  In Assembly, SETLFS doesn't take anything in the accumulator for LOAD/SAVE calls.  And, the "VRAM bank + 2" is put into the accumulator of the LOAD call (i.e., the 17-bit VRAM address is given directly to the LOAD call).


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Sat Dec 25, 2021 2:28 pm
by rje

THANK YOU!  Now some more questions.

lda #<$8000

ldx #>$8000

Are the < and > operators how we split a word into low and high bytes?

 

Second question.  Can I just directly increment a memory location, and use the carry bit to increment the high byte?

That might look messier than nested loops...


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Sat Dec 25, 2021 2:31 pm
by rje

And, merry Christmas!


Assembly: How to save RAM, and how to print RAM to the screen

Posted: Sat Dec 25, 2021 2:59 pm
by Stefan


On 12/25/2021 at 4:28 PM, rje said:




lda #<$8000

ldx #>$8000



Are the < and > operators how we split a word into low and high bytes?



Yes.


On 12/25/2021 at 4:28 PM, rje said:




Can I just directly increment a memory location, and use the carry bit to increment the high byte?



I'm not sure what you exactly mean. However, the INC, INX, INY, and INA opcodes don't affect the carry bit, so I guess the answer is no.

In @Greg King's post above, there is a complete code sample using the Y register to walk through the low byte of the address. As may be seen in the sample, wrap around of Y is tested by checking for 0, not carry (the row BNE LOOP in Greg's code).