Login
Back to forumReply to this topicGo to last reply

Posted By

Haegar
on 2025-09-10
05:23:48
 PRINTing Machine Code instead of POKEing

Hello,

Someone asked an interesting question in a German forum (https://forum.classic-computing.de/forum/index.php?thread/36938-print-als-schnelleres-poke/). He want to load machine code (MC) into the memory from a BASIC program, not using the DATA statement and POKE, he wants to use the PRINT statement. Apparently, this is supposed to be faster and is supposedly also a common practice on the C64. To get the code into the correct memory location by using the PRINT statement, the video RAM would have to be shifted. Has anyone tried this?

To avoid further questions: he don't want to load the machine code program separately or save it directly with the BASIC program.

I don't want to talk about the sense or nonsense of the method here, but it sounds like an interesting technique.
Posted By

Csabo
on 2025-09-10
08:31:39
 Re: PRINTing Machine Code instead of POKEing

Yes, this is doable. Using the BASIC PRINT Statement is essentially the same thing as POKE, you're writing bytes to the RAM. It can get tricky for some special characters, but otherwise it's obviously much faster than individual POKEs.

Here's a very simple proof of concept.
[ print_ml_code_example.prg ]

Also, this is definitely not widely used on Plus/4. TBH I can't think of any examples where I would have seen this.
Haegar1
Posted By

64erGrufti
on 2025-09-11
03:01:24
 Re: PRINTing Machine Code instead of POKEing

I'm the asker. No, that's not the solution for my prolem.
I know generally how to print. My problem is, how I can move the screen memory to do the address I want? And maybe the next problem is that the color ram is connected to the screen ram. With the print I would like to print only in the screen ram. The color ram has to be as it is.
How can I move the screen ram, print to it and move it later back? All my tries at this time doesn't work.
I tried to poke $ff14. The displayed chars where changed but the print was done to the old memory address. I also tried to modify $0288, but it doesn't work too. The only I doesn't tried until now is to combinate both.
Posted By

Csabo
on 2025-09-11
08:33:24
 Re: PRINTing Machine Code instead of POKEing

Hey 64erGrufti, welcome happy

What you're saying is not possible AFAIK. You can change the character screen's location with a POKE to $FF14, but you won't be able to type there, or PRINT or CHAR.

The relevant code in the ROM is at $D8AF. This sets the color and character pointers, but it uses a fixed lookup table that always points to $0C00; in other words, it ignores the value of $FF14.

I'm not familiar with $0288, I quickly looked it up in the Ultimate Map ( <-- recommended!), but it just says "Disk output string area", so I'm not sure that's related to the screen at all.

So where does that leave us?

It is possible to "modify the ROM" (you copy the ROM to the RAM happy), so you could in theory fix that part to take $FF14 into consideration, but that's way too much effort, and a loss of 32K RAM. IMHO doing that would be much harder than other solutions.

If you just need a one-time ML routine, you could print that to the regular screen, that's already established. You can also "hide" your ML code in BASIC lines (as long as you don't use $00 in it), and call it with a regular SYS. You could simply save your ML code behind your BASIC program, and reset the pointers in the beginning. That way your ML code is already in memory, doesn't need to be POKEd or PRINTed at all.

Without knowing the exact use case, that's all I can think of. Hope it helps! happy
Posted By

64erGrufti
on 2025-09-11
11:46:45
 Re: PRINTing Machine Code instead of POKEing

Oh sorry, $0288 was the address in the C64. The correspond address in the Plus4 should be $53E.
If it is not possible to print to other addresses then the Plus4 differs from the C64. On this it is possible.

Thanks for your help. Then I have to solve it in an other way.
Posted By

Haegar
on 2025-09-11
13:39:31
 Re: PRINTing Machine Code instead of POKEing

I just tested it again and couldn't change the vector for the PRINT command. I think the best way to do is turn off the screen and poke the code.
Posted By

SVS
on 2025-09-11
14:55:10
 Re: PRINTing Machine Code instead of POKEing

Interesting idea, but not operative IMO. The machine code surely has non-alphanumeric characters that would make not linear the printing over the memory.
Posted By

64erGrufti
on 2025-09-12
02:29:59
 Re: PRINTing Machine Code instead of POKEing

@SVS
On C64 it works perfectly. The only problem on the Plus4 is that you can't print to other addresses.
C64Studio has integrated a Bin2Print converter. With this it works on the C64. You have to take note that you print screencodes, not PETSCII.
Posted By

gerliczer
on 2025-09-13
09:11:40
 Re: PRINTing Machine Code instead of POKEing

A workaround to this problem could be 1) Turn off screen 2) Print to screen memory 3) Copy from screen memory to final destination (the following topic has a solution to do that quite swiftly: /forum/16973) 4) Clear screen and turn it back on


Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2025. Support Plus/4 World on Patreon