Self Modifying Basic Code

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
User avatar
GCHarder
Posts: 427
Joined: Sat Dec 14, 2013 7:46 pm

Self Modifying Basic Code

Post by GCHarder »

Code: Select all

#SELF MODIFYING CODE: REPLACES LET O0=0, LET O1=1...LET OE=14, LET OF=15
  100 FOR N=0 TO 15
  110 POKE PEEK 16425+256*PEEK 16426+6,N+28
  120 LET 0X=N
  130 NEXT N
  140 PRINT 00,01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F
Here's a code snippet you may be interested in.

System variable 16425 NXTLIN "The Address of next program line to be executed, " is used to define a series of variables.

In this example, I'm assuming the purpose is to define a series of variables representing Hex numbers Oo=0, O1=1....OE=14, OF=15. You could define variables all the way up to OZ if you wanted.

I've used this technique before, to save RAM. Unfortunatly I don't know where I got it from...heck maybe I came up with it, who knows!

FYI, NXTLINE is also often used to call "Inline" MC routines, which can float around in the BASIC area. Works nicely as long as only relative jumps are used.

Regards;

Greg
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Self Modifying Basic Code

Post by sirmorris »

Ooooh I've seen some dirty tricks in my time but that's a classic :D
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: Self Modifying Basic Code

Post by Shaun_B »

How dirty can you get then? Any other 'dirty' tricks worth mentioning?

Regards,

Shaun.
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Self Modifying Basic Code

Post by 1024MAK »

I've seen something similar to call a short m/c routine that could be anywhere in the BASIC listing (no absolute address modes though).

Nice to see the "how" :D

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
GCHarder
Posts: 427
Joined: Sat Dec 14, 2013 7:46 pm

Re: Self Modifying Basic Code

Post by GCHarder »

Here's a program which uses NXTLIN to call a couple MC routines.

Regards;

Greg
Attachments
Partial Screen Clear.zip
Partial Screen Clear and CLS MC routines.
(157.27 KiB) Downloaded 218 times
User avatar
GCHarder
Posts: 427
Joined: Sat Dec 14, 2013 7:46 pm

Re: Self Modifying Basic Code

Post by GCHarder »

Here's another example of self-modifying BASIC code.
Attachments
Graphics Loop.zip
Self-modifying code examples
(160.49 KiB) Downloaded 235 times
Post Reply