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

Tutorials and help articles.

(Posts require approval. See pinned post.)
Forum rules
Post guides, tutorials, and other instructional content here.

This topic area requires approval, so please be patient while we review content to make sure it fits the expectations for this topic area.

Tech support questions should be asked in Hardware or Software support.
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

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

Post 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

 

TomXP411
Posts: 1781
Joined: Tue May 19, 2020 8:49 pm

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

Post 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
Greg King
Posts: 162
Joined: Wed Jul 08, 2020 1:14 pm

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

Post 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

Greg King
Posts: 162
Joined: Wed Jul 08, 2020 1:14 pm

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

Post 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.)

ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

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

Post 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)

ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

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

Post 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.

Greg King
Posts: 162
Joined: Wed Jul 08, 2020 1:14 pm

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

Post 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).

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

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

Post 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...

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

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

Post by rje »


And, merry Christmas!

Stefan
Posts: 454
Joined: Thu Aug 20, 2020 8:59 am

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

Post 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).

Post Reply