Author Topic: My own boot sector which starts a basic program  (Read 391 times)

0 Members and 1 Guest are viewing this topic.

Offline pmeier

  • CPC464
  • **
  • Posts: 27
  • Country: de
  • Liked: 7
I was thinking about creating my own disk protection system. Just for fun.
As I'm no assembler expert, so I want to write BASIC wherever possible.
So for a professional look the disk can be booted, but starts a BASIC program. (Which checks if there is a special sector with RSX commands...)

I found a good example how to start a BASIC program from assembly in this forum.
Surprisingly it didn't work on 664/6128 when run from boot sector. Standalone it worked perfectly and on 464 even as boot program.
I checked my system handbook and found an additional value to initialize, which fixed it. Here is the whole program:

Code: [Select]
;;
;; program for boot sector: just executes run"disc
;;

;; WARNING: This binary has to fit in &100-&16f!!!

cas_in_open equ &bc77
cas_in_direct equ &bc83
cas_in_close equ &bc7a
mc_start_program equ &bd16
kl_rom_select equ &b90f
kl_rom_walk equ &bccb

org &100

;; http://www.cpcwiki.eu/index.php/Programming:Loading_a_file
ld c,&ff ;; disable all roms
ld hl,start ;; execution address for program
call mc_start_program ;; start it

start:
call kl_rom_walk    ;; enable all roms

load_file:
ld b,end_filename-filename
ld hl,filename
ld de,0

call cas_in_open

ld hl,&170
call cas_in_direct
call cas_in_close

call basic
;; will not return

.filename
defb "disc"
.end_filename

;; run BASIC
;; this executes the currently loaded BASIC program from the beginning
;; http://www.cpcwiki.eu/forum/programming/stuck-with-run-basic-program-from-asm/msg65327/#msg65327
basic:
ld hl,&1fff        ;; maximum length of currently loaded BASIC program
ld bc,&170
add hl,bc
ld c,0
call kl_rom_select
ld a,(&c002)
cp 0
jp z,cpc464

;; required if this runs as boot sector on 664/6128 (seems that 464 does not need that)
;; found out myself... very proud ;-)
;; XXX BASIC list command shows nothing... but it is executed from boot sector
ld de,&40
ld (&ae62),de ;; &ae7f for 464
ld de,&16f
ld (&ae64),de ;; &ae81 for 464

ld (&ae66),hl
ld (&ae68),hl
ld (&ae6a),hl
ld (&ae6c),hl
cp 1
jp z,cpc664
jp &ea78        ;; run BASIC CPC6128
.cpc664
jp &ea7d        ;; run BASIC CPC664
.cpc464
ld (&ae83),hl
ld (&ae85),hl
ld (&ae87),hl
ld (&ae89),hl
jp &e9bd        ;; run BASIC CPC464

Maybe someone can explain why 664/6128 requires the additional code.
And another annoyance: for 664/6128 the BASIC program is deleted after execution.
Looks like as if it was protected. What's wrong here?

Currently the program meets it requirements, but comments are appreciated  :)

Offline SOS

  • Supporter
  • CPC6128
  • *
  • Posts: 210
  • Country: de
  • Identity lost
    • index.php?action=treasury
  • Liked: 132
Re: My own boot sector which starts a basic program
« Reply #1 on: 02:14, 17 June 17 »
....
ld (&ae89),hl
jp &e9bd        ;; run BASIC CPC464
...
Hmm....
I'm using a lot of more code, to run a BASIC-Program (for CPC464):

Code from C012 from the BASIC-ROM:

Code: [Select]
; Some Inits from the BASIC-ROM
ld hl,&ac00
ld (hl),&00
ld b,&1b
lc019:
inc hl
ld (hl),&c9
djnz lc019

xor a
ld (&ac00),a
call &ddcb
call &ca84
call &bd97
call &c0d3
ld de,&f0
call &f706
ld hl,&41
jp &e9bd        ;; run BASIC CPC464

And another annoyance: for 664/6128 the BASIC program is deleted after execution.
Looks like as if it was protected. What's wrong here?

Currently the program meets it requirements, but comments are appreciated  :)
How looks the value of the adress &AE2C on the 664/6128?
Acts the Amstrad different, if you set the &AE2C to Zero?


Added (Forget your question):
Maybe someone can explain why 664/6128 requires the additional code.
it's strange that the 464 doesn't need the init of &ae7f , &ae81.
When you take a look at &c00c at the 464ROM, you will see that &F4C4-Routine will be set the RAM-adresses.

« Last Edit: 09:40, 17 June 17 by SOS »

Offline pmeier

  • CPC464
  • **
  • Posts: 27
  • Country: de
  • Liked: 7
Re: My own boot sector which starts a basic program
« Reply #2 on: 12:15, 17 June 17 »
I'm using a lot of more code, to run a BASIC-Program (for CPC464):

Well, I'm just using the example from:
http://www.cpcwiki.eu/forum/programming/stuck-with-run-basic-program-from-asm/msg65327/#msg65327

How looks the value of the adress &AE2C on the 664/6128? Acts the Amstrad different, if you set the &AE2C to Zero?

It contains the value 2. If I set it to zero the listing is not deleted! Great. How did you know that?
UPDATE: Ah, it's the address for protected BASIC says my system manual. Thank you. You see I'm still learning.

it's strange that the 464 doesn't need the init of &ae7f , &ae81.

OK. Currently I'm just testing with WinAPE. Next step would be my real 464, but I want to be platform independent.  ;)
« Last Edit: 12:19, 17 June 17 by pmeier »

Offline SOS

  • Supporter
  • CPC6128
  • *
  • Posts: 210
  • Country: de
  • Identity lost
    • index.php?action=treasury
  • Liked: 132
Re: My own boot sector which starts a basic program
« Reply #3 on: 17:25, 17 June 17 »
Well, I'm just using the example from:
http://www.cpcwiki.eu/forum/programming/stuck-with-run-basic-program-from-asm/msg65327/#msg65327

It's a short form of "i want to start a BASIC program".
I Need a longer version in my program, because i can not be sure, if the BASIC is successful initialized.
(e.g. 664-Amsoft-Welcome-Disc (i cant remember  :'( ) doesn't run completely)
When your addresses &ae7f , &ae81 are not set correctly, i think, that you have not a correct BASIC-init (?!).



It contains the value 2. If I set it to zero the listing is not deleted! Great. How did you know that?
UPDATE: Ah, it's the address for protected BASIC says my system manual. Thank you. You see I'm still learning.

OK. Currently I'm just testing with WinAPE. Next step would be my real 464, but I want to be platform independent.  ;)

A great function are the "Breakpoint on Write" function in Winape.
So you can set them, e. g. at &170 and see, when will the address be overwritten (deleted)  :)
Additional I'm using "ROM-Listing_CPC(Janneck_Mossakowski).pdf" to check what's going on in the 464ROM.