Start of current BASIC program [message #36170] |
Thu, 07 February 2013 18:10 |
jgharston
Messages: 12 Registered: February 2012
Karma: 0
|
Junior Member |
|
|
Can a running program find where it is in memory so a SYS call will
call the correct place in memory?
On the C64 I have a machine code program with a BASIC bootstrap at the
beginning:
10SYS2061
(My machine code at MEMBOT+13 is position independent and relocates
itself.)
However, on the C128 the BASIC program will be in memory at $1C00 not
$0800. I had initially thought of doing something like SYS
PEEK(641)+256*PEEK(642)+13, but MEMBOT is stored in a different
location on the C128.
JGH
|
|
|
Re: Start of current BASIC program [message #36451 is a reply to message #36170] |
Fri, 08 February 2013 01:28 |
rusure
Messages: 1030 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Thursday, February 7, 2013 4:10:21 PM UTC-7, jgharston wrote:
> Can a running program find where it is in memory so a SYS call will
> call the correct place in memory?
>
>
>
> On the C64 I have a machine code program with a BASIC bootstrap at the
> beginning:
>
> 10SYS2061
>
> (My machine code at MEMBOT+13 is position independent and relocates
>
> itself.)
>
>
>
> However, on the C128 the BASIC program will be in memory at $1C00 not
>
> $0800. I had initially thought of doing something like SYS
>
> PEEK(641)+256*PEEK(642)+13, but MEMBOT is stored in a different
The first byte following a C128 BASIC program in bank 0 is given by the values in $1210 (+4624) for the low order byte and $1211 for the high order byte in bank 0. No addition is needed to offset for the length of the program. I can't find the memory location containing the first byte of a C128 BASIC program. It depends on whether the C128 is running in text or graphics modes. If you have a real spaghetti bowl of a program, you may want to devote a separate program variable to keep track of the location of the program's first byte. $1c00 (+7168) for a program in text mode or $4000 (+16384) for a program in graphics mode.
|
|
|
|
Re: Start of current BASIC program [message #36500 is a reply to message #36483] |
Fri, 08 February 2013 18:07 |
rusure
Messages: 1030 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Friday, February 8, 2013 10:50:44 AM UTC-7, jgharston wrote:
> So it looks like the bootstrap code is going to have to be something
>
> like
>
> 10IF(something)THENSYS7212
>
> 20SYS2092
>
>
>
> but what test would I need to use?
>
>
>
> JGH
If you are trying to determine if you're in 64 or 128 mode, the easiest test is IFFRE(0)<>FRE(1). You also need a STOP command after the C128 SYS to prevent a C64 SYS from executing in the next line The code would be shorter if you
I find it easier to execute the c64 code on the condition of FRE(0)=FRE(1)
Here is a sample program
10 iffre(0)=fre(1):poke2096,8:sys2092:stop
20 sys7212
1c2c ldx #$05
1c2e lda 1c38,x
1c31 jdr $ffd2
1c34 dex
1c35 bpl $1c2e
1c37 rts
1c38 0d 45 52 45 48 93
e r e h clr screen
|
|
|
Re: Start of current BASIC program [message #36501 is a reply to message #36500] |
Fri, 08 February 2013 18:09 |
rusure
Messages: 1030 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Friday, February 8, 2013 4:07:12 PM UTC-7, rusure wrote:
> On Friday, February 8, 2013 10:50:44 AM UTC-7, jgharston wrote:
>
>> So it looks like the bootstrap code is going to have to be something
>
>>
>
>> like
>
>>
>
>> 10IF(something)THENSYS7212
>
>>
>
>> 20SYS2092
>
>>
>
>>
>
>>
>
>> but what test would I need to use?
>
>>
>
>>
>
>>
>
>> JGH
>
>
>
> If you are trying to determine if you're in 64 or 128 mode, the easiest test is IFFRE(0)<>FRE(1). You also need a STOP command after the C128 SYS to prevent a C64 SYS from executing in the next line The code would be shorter if you
>
>
>
> I find it easier to execute the c64 code on the condition of FRE(0)=FRE(1)
>
> Here is a sample program
>
>
>
> 10 iffre(0)=fre(1):poke2096,8:sys2092:stop
>
> 20 sys7212
>
>
>
> 1c2c ldx #$05
>
> 1c2e lda 1c38,x
>
> 1c31 jdr $ffd2
>
> 1c34 dex
>
> 1c35 bpl $1c2e
>
> 1c37 rts
>
> 1c38 0d 45 52 45 48 93
>
> e r e h clr screen
|
|
|
|
Re: Start of current BASIC program [message #36521 is a reply to message #36170] |
Fri, 08 February 2013 23:35 |
sjgray
Messages: 53 Registered: April 2012
Karma: 0
|
Member |
|
|
On Thursday, February 7, 2013 6:10:21 PM UTC-5, jgharston wrote:
> Can a running program find where it is in memory so a SYS call will
>
> call the correct place in memory?
>
>
>
> On the C64 I have a machine code program with a BASIC bootstrap at the
>
> beginning:
>
> 10SYS2061
>
> (My machine code at MEMBOT+13 is position independent and relocates
>
> itself.)
>
>
>
> However, on the C128 the BASIC program will be in memory at $1C00 not
>
> $0800. I had initially thought of doing something like SYS
>
> PEEK(641)+256*PEEK(642)+13, but MEMBOT is stored in a different
>
> location on the C128.
>
>
>
> JGH
There is probably a better approach, but you could use the brute-force method. Add a little "header" after your basic loader, and before the start of your ML code, something like "XYZ", then do a short loop through memory to find it.
Steve
|
|
|
Re: Start of current BASIC program [message #36582 is a reply to message #36170] |
Sun, 10 February 2013 01:29 |
rusure
Messages: 1030 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Thursday, February 7, 2013 4:10:21 PM UTC-7, jgharston wrote:
> Can a running program find where it is in memory so a SYS call will
> call the correct place in memory?
>
> On the C64 I have a machine code program with a BASIC bootstrap at the
> beginning:
> 10SYS2061
> (My machine code at MEMBOT+13 is position independent and relocates
> itself.)
>
> However, on the C128 the BASIC program will be in memory at $1C00 not
> $0800. I had initially thought of doing something like SYS
> PEEK(641)+256*PEEK(642)+13, but MEMBOT is stored in a different
> location on the C128.
>
Since my last post to this thread, I have indeed discovered memory locations containing the pointer to the beginning of BASIC programs. For the C64, the pointer is in $2b (+43) and $2c. For the C128 $2d (+45) and $2e contain the pointer. The following program is more fun than my first program. In C128 mode,the program assumes that $2d contain a value of 1 and be of length less than 257 bytes. It's the source code for the MADS assembler. The first section contains the tokenized BASIC boot program listed in the comment lines. The second section is the assembly language of the audio program.. The entire program works in both C64 and C128 modes, when loaded like an ordinary BASIC program. I have uploaded a ZIP archive containing the petscii source code, the commodore binary, and the .txt source code in the standard ascii character set. Here is the archive:
https://docs.google.com/file/d/0B80L9cEZ8YnvNkY2a0taVUdDblk/ edit?usp=sharing
*=$1c01
;10 s=peek(46)*256+55:iffre(0)=fre(1)thens=peek(44)*256+65
;20 syss
..dby $2e1c,$0a00
..byt 's',$b2,$c2,'(46)',$ac,'256',$aa,'55:'
..byt $8b,$b8,'(0)',$b2,$b8,'(1)',$a7
..byt 's',$b2,$c2,'(44)',$ac,'256',$aa,'65',$00
..dby $351c,$1400,$9e53,$0000
..byt $00
c128 lda $2e;entry point when in c128 mode
ldy #<ldreg+1
sta ($2d),y
ldy #<ldval+1
sta ($2d),y
c64 ldy #$8;entry point when in c64 mode
ldreg ldx sidrg3-$1400,y
ldval lda sidvl3-$1400,y
sta $d400,x
dey
bpl ldreg
rts
sidrg3 .byt $45,$04,$04,$18,$0f,$0e,$06,$05,$00
sidvl3 .byt $02,$14,$15,$0f,$19,$c3,$fe,$0c,$3c
..end
|
|
|
Re: Start of current BASIC program [message #210477 is a reply to message #36582] |
Mon, 25 November 2013 09:31 |
Martin 'Martinland' S
Messages: 61 Registered: January 2012
Karma: 0
|
Member |
|
|
On Fri, 08 Feb 2013 00:10:21 +0100, jgharston wrote:
> Can a running program find where it is in memory so a SYS call will
> call the correct place in memory?
On Sun, 10 Feb 2013 07:29:41 +0100, rusure wrote:
> The entire program works in both C64 and C128 modes, when loaded like an
> ordinary BASIC program. I have uploaded a ZIP archive containing the
> petscii source code, the commodore binary, and the .txt source code
Cool, thanks for sharing another interesting thread!
RTS,
ML
READY.
|
|
|