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

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.

Post Reply

  • Print view

16 posts

  • 1
  • 2
  • Next
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

  • Quote

Postby 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

Top

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

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

  • Quote

Postby 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

Top

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

  • Quote

Postby 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

Top

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

  • Quote

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

Top

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

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

  • Quote

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

Top

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

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

  • Quote

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

Top

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

  • Quote

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

Top

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

  • Quote

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

Top

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

  • Quote

Postby rje »

And, merry Christmas!

Top

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

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

  • Quote

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

Top

Post Reply

  • Print view

16 posts

  • 1
  • 2
  • Next

Return to “Guides and Tutorials”

Jump to

  • Forums
  • ↳ Official Announcements
  • ↳ X16 Bug Reporting
  • ↳ Introductions
  • ↳ Commander X16 Forums
  • ↳ CX16 General Chat
  • ↳ Programming
  • ↳ Guides and Tutorials
  • ↳ CX16 Hardware Support
  • ↳ X16 Software Support
  • ↳ X16 Feature Requests
  • ↳ Website Feedback And Support
  • ↳ Murray2 CX16 Discussion Archive
  • ↳ Works In-Progress Discussion
  • ↳ Libraries and Examples
  • ↳ Help Wanted
  • ↳ Trade, Buy, Sell
  • Downloads
  • ↳ Official Software
  • ↳ Games
  • ↳ Productivity Apps
  • ↳ Graphics Apps
  • ↳ Audio Apps
  • ↳ Development Tools
  • ↳ Libraries And Demo Code
  • ↳ Emulation, PC Connectivity, Networking
  • ↳ Misc Apps
  • ↳ Tutorials
  • ↳ Demoscene
  • ↳ WIP Demos
  • ↳ Archive
  • ↳ Program Requests, Suggestions, Ideas
  • ↳ Monarch Open ROM
  • ↳ Video/Podcast talk
Assembly: How to save RAM, and how to print RAM to the screen (2025)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Kieth Sipes

Last Updated:

Views: 5878

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.