English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. Tutorials (http://eab.abime.net/forumdisplay.php?f=73)
-   -   2k intro boot... (http://eab.abime.net/showthread.php?t=98927)

D4Ni3L3 22 September 2019 18:43

2k intro boot...
 
I just want to ask your help for something I always have been wondering about for many years...

let's get to it:

Assuming I have any 2k executable intro and want to experience how to write it into the bootblock can I do this job with the ASM-One/ARIII or do I need any special tool?

Sorry to ask, but I am lin the dark.....

ross 22 September 2019 18:54

Quote:

Originally Posted by D4Ni3L3 (Post 1347133)
I just want to ask your help for something I always have been wondering about for many years...

let's get to it:

Assuming I have any 2k executable intro and want to experience how to write it into the bootblock can I do this job with the ASM-One/ARIII or do I need any special tool?

Sorry to ask, but I am lin the dark.....

Booblock itself is only 1KB so you have to load the 2 additional sectors.
I have no idea if there is a special tool, but if you want I will do it for you ;)

D4Ni3L3 22 September 2019 19:14

Quote:

Originally Posted by ross (Post 1347134)
Booblock itself is only 1KB so you have to load the 2 additional sectors.
I have no idea if there is a special tool, but if you want I will do it for you ;)

Thanks... but I prefer learn how to do it! ;)

Then ... assuming I have a 1k code to jam into the bootblock sectors ... how to do it?

ross 22 September 2019 19:29

Quote:

Originally Posted by D4Ni3L3 (Post 1347137)
Thanks... but I prefer learn how to do it! ;)

Then ... assuming I have a 1k code to jam into the bootblock sectors ... how to do it?

In (relocated) binary form or source code?

D4Ni3L3 22 September 2019 19:38

Quote:

Originally Posted by ross (Post 1347143)
In (relocated) binary form or source code?

executable...

ross 22 September 2019 19:47

Ok, two possibilities:

1) the exe is fully pc relative, so you do not need to relocate it.
Simply strip the header (at start and end of the binary).
Then assemble:

Code:

bb:
  dc.b 'DOS',0
  dc.l checksum
  dc.l $370
start: incbin "your.exe"

If you want to launch system you need a little stub at end.

2) relocate the exe at some fixed location.
Then:
Code:

bb:
  dc.b 'DOS',0
  dc.l checksum
  dc.l $370
start: copy bin to right location
bin: incbin "your.exe"

But an real example sure is better :)

phx 22 September 2019 20:26

Quote:

Originally Posted by ross (Post 1347148)
Simply strip the header (at start and end of the binary).

Not sure if this will be simple for a beginner, without knowledge of the hunk format structure. :)

To simplify it: if you have a single-section executable the header will be 32 bytes, which you can skip. But then you lose this space in the boot block.
Code:

bb:
  dc.b 'DOS',0
  dc.l checksum
  dc.l $370
start:
  bra.b *+34
  incbin "your.exe"

Better would be to let your assembler write a raw binary file, without hunk format headers. With vasm it would be -Fbin, but IIRC you are using AsmOne? So you may assemble to memory and then save the memory contents to a file (wb command?).

a/b 22 September 2019 20:54

For asm-one:
1. use this source:
Code:

start:
 DC.B 'DOS',0
 DS.L 1  ; checksum comes here
 DC.L 880

exe_code:
 DS.B 1024-12
end:

2. assemble the source with A
3. load exe into memory with RO, you will get its memory location, say it's X
4. copy exe with C (beg is X, end is X+1024-12, dest is exe_code)
5. write bb to disk as 2 sectors with WS (ram ptr is start, disk ptr is 0, length is 2)
6. calculate bootblock checksum with CC

Edit: Forgot to mention, you can simulate bootblock with BS (beg is start).

ross 22 September 2019 22:45

1 Attachment(s)
A real example: "It's a sin" by Planet Jazz.
It's a 1KB bootblock intro with source code available, full PC relative.

I chose this because I took the opportunity to fix some small bugs that prevents it to exit to CLI regularly.

Greeting to the original coder :)

Code:

;Planet Jazz - It's a sin bootblock for Datastorm 2017
;Partycoded by Olle using Blueberrys bootblock examplecode.
;It's not only a sin, it is also a complete mess. :)

; little fix by ross 22/09-2019

; Bootblock example code by Blueberry / Loonies, 23/9-2012
; Public Domain

; System constants
_LVOFindResident = -96
_LVOLoadView = -222
_LVOWaitTOF = -270
gb_ActiView = 34
gb_copinit = 38
IVBLIT = 156
RT_INIT = 22
SU_tf_CharData = $22
SU_OpenFont = -72

_AUD0LCH = $A0
_AUD0LEN = $A4
_AUD0PER = $A6
_AUD0VOL = $A8
_AUD2LCH = $C0
_AUD2LEN = $C4
_AUD2PER = $C6
_AUD2VOL = $C8

Mask = 2048-1


        section        BB,code

; The bootblock starts here.
; It cannot generally be assumed to be placed in a specific
; kind of memory, or at any specific address, so all code
; must be completely PC relative, and all chip data must
; be explicitly copied to chip memory.

BB:
        DC.B        'DOS',0
        DC.L        0
        DC.L        $370

START:
        ; Bootblock code goes here.
        movem.l        d0-a6,-(sp)

        ; Global pointer to chip space in A4
        ; Chip space at the end of (512k) chip memory
        lea        $80000-4096-(Space_End-Space),a4

        ; Open topaz
;        movea.l        $4.w,a6
        movea.l        IVBLIT(a6),a6        ; graphics.library
        lea        TextAttr(pc),a0
        lea        TopazName(pc),a1
        move.l        a1,(a0)
        jsr        SU_OpenFont(a6)
        movea.l        d0,a0
        move.l        SU_tf_CharData(a0),TopazCharData-Space(a4)

        lea        TextScr-Space(a4),a0
        lea        Bpl2-Space(a4),a1
        move.w        #$00e4,d1
        bsr.w        SetBpl
        addq.w        #2,d1
        adda.l        #(80*1)+2,a0
        bsr.w        SetBpl

        lea        Kottig_Text(pc),a0
        lea        TextMsg-Space(a4),a1
        moveq        #(Kottig_TextE-Kottig_Text)/4-1,d7
.tloop        move.l        (a0)+,(a1)+
        dbf        d7,.tloop

        ; Copy copperlist to chip
        lea        CopperData(pc),a0
        lea        Copper-Space(a4),a1
        moveq        #(CopperData_End-CopperData)/4-1,d7
.cloop        move.l        (a0)+,(a1)+
        dbf        d7,.cloop

        move.l        #$00280078,Yptr1-Space(a4)
       
        lea        TextMsg-Space(a4),a0
        move.l        a0,Textptr-Space(a4)

        lea        $DFF000,A5
        move.w        2(a5),-(sp)
        ori.w        #$8000,(sp)

        ;init sound
        lea        Waveform-Space(a4),a1
        move.w        #$7f80,(a1)

        move.l        a1,_AUD0LCH(a5)
        move.w        #1,_AUD0LEN(a5)
        move.l        a1,_AUD2LCH(a5)
        move.w        #1,_AUD2LEN(a5)

;        bsr.w        gen_sin
        lea        Bpl_Sinus-Space(a4),a0
        lea        1024(a0),a1
        moveq        #0,d4
        move        #256-1,d3
.l1        move.l        d4,d0
        swap        d0
        add.l        #823550,d4        ;Pi<<18
        move        d0,d2
        move        d0,d1
        mulu        d1,d1
        lsl.l        #4,d1
        swap        d1
        mulu        d1,d0
        divu        #3<<11,d0
        sub        d0,d2
        mulu        d1,d0
        divu        #10<<11,d0
        add        d0,d2
        mulu        d1,d0
        divu        #21<<11,d0
        sub        d0,d2
        asr        #4,d2

        move        d2,(a0)+
        move        d2,2046(a0)
        move        d2,-(a1)
        neg        d2
        move        d2,1022(a0)
        move        d2,1024(a1)
        dbf        d3,.l1


;        bsr.w        render_triangle
        moveq        #0,d1
        moveq        #0,d7
        lea        TScreen-Space(a4),a0
        move.l        #640/2,d0
.floop        subq.l        #1,d0
        add.l        #80,d1
        move.w        d7,d2
        lsl.w        #1,d2

        move.l        d0,d3
.fscanl
;        bfset        (a0,d1.w){d3:01}                ; 68020+ method
; 68000-method ;(
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        move.l        d3,d4                                ; x
        move.l        d1,d5                                ; y
        ror.l        #3,d4
        add.l        d4,d5                                ; + x position in bit(!)[*]
        rol.l        #3,d4                                ; /8 - now we have byte offset
        not        d4                                ; correct offset for bitset
        bset        d4,(a0,d5.w)
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        addq.l        #1,d3
        dbra        d2,.fscanl

        addq.w        #1,d7
        cmp.w        #320,d7
        bne.b        .floop

;        bsr.w        fill_copper
        lea        Bplist-Space(a4),a0
        move.l        #$1ee1fffe,d0
        move.l        #300-1,d1
.fill        move.l        d0,(a0)+
        move.l        #$00e00000,(a0)+
        move.l        #$00e20000,(a0)+
        add.l        #$01000000,d0
        dbra        d1,.fill

        ; Set copperlist
        lea        Copper-Space(a4),a1
        move.l        a1,$80(a5)

        ; Disable interrupts and set some DMAs
        move.w        #$4000,$9a(a5)
        move.w        #$87C5,$96(a5)
;        move.w        #%1000000000000101,_DMACON(a5)

        ; Switch off sprite DMA
;        bsr.w        WaitVbl
        move.w        #$0020,$96(a5)

        ; Main per-frame loop
MainLoop
;        bsr.w        do_sine
        move.w        Yptr1-Space(a4),d2
        move.w        Yptr2-Space(a4),d3
        lea        Bpl_Sinus-Space(a4),a0
        lea        TScreen-Space(a4),a1                ; Triangle screen
        lea        Bplist-Space(a4),a2
        move.l        #300-1,d7
.loop        move.w        (a0,d2),d4
        add.w        (a0,d3),d4
        asr.w        #2,d4
        add.w        #100,d4
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        mulu        #80,d4
        add.l        a1,d4
        move.w        d4,10(a2)
        swap        d4
        move.w        d4,6(a2)
        add.l        #12,a2
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        add.w        #8*4,d2
        add.w        #4*4,d3
        and.w        #Mask,d2
        and.w        #Mask,d3
        dbra        d7,.loop
        move.w        Yptr1-Space(a4),d2
        move.w        Yptr2-Space(a4),d3       
        add.w        #2*4,d2
        add.w        #4*4,d3
        and.w        #Mask,d2
        and.w        #Mask,d3
        move.w        d2,Yptr1-Space(a4)
        move.w        d3,Yptr2-Space(a4)

        bsr.w        write_text
       
;-------------- audio --------------
;do_drum
        cmp.w        #32,Ticks-Space(a4)
        bne.b        .ntrig
        move.w        #124,Per-Space(a4)
        move.w        #64,Vol-Space(a4)
        clr.w        Ticks-Space(a4)
.ntrig
        addq.w        #1,Ticks-Space(a4)

        move.w        Per-Space(a4),_AUD0PER(a5)
        move.w        Vol-Space(a4),_AUD0VOL(a5)

        add.w        #12<<8,Per-Space(a4)
        subq.w        #8,Vol-Space(a4)

        move.w        Per-Space(a4),_AUD2PER(a5)
        move.w        Vol-Space(a4),_AUD2VOL(a5)
;----------------------------------
        bsr.b        WaitVbl

        ; Loop until LMB
        btst        #6,$bfe001
        bne.w        MainLoop

Exit:
        ; Recover DMA settings
        move.w        #$7fff,$96(a5)
        move.w        (sp)+,$96(a5)

        ; Restore copper
;        move.l        IVBLIT(a6),a6
        move.l        gb_copinit(a6),$80(a5)

        ; Restore registers
        movem.l        (sp)+,d0-a6

        ; Return init function of dos.library resident in A0
        lea        DosName(pc),a1
        jsr        _LVOFindResident(a6)
        movea.l        d0,a0
        movea.l        RT_INIT(a0),a0
        moveq        #0,d0
        rts

WaitVbl
        tst.b        5(a5)
        beq.b        WaitVbl
.wvb
        tst.b        5(a5)
        bne.b        .wvb
        rts

SetBpl
        move.l        a0,d0
        move.w        d1,(a1)+        ;$00ex
        swap        d0
        move.w        d0,(a1)+        ;h
        swap        d0
        addq.w        #2,d1
        move.w        d1,(a1)+        ;$00ex
        move.w        d0,(a1)+        ;l
        rts

;-----------------------------------

; Textwriter using Topaz font.
write_text
        lea        TextScr-Space(a4),a1
        adda.l        #80*8+20-2+((80*10)*5),a1

        movea.l        Textptr-Space(a4),a0
.getch        moveq        #0,d0
        move.b        (a0)+,d0
        beq.b        .fin                        ; if 0 then finished
        move.l        a0,Textptr-Space(a4)

        tst.b        d0                        ; repeat space $7f+no of spaces
        bpl.b        .norepspace
        sub.w        #$7f,d0
        add.w        d0,TextCursorx-Space(a4)
        bra.b        .getch
.norepspace

        cmp.b        #10,d0                        ; newline
        bne.b        .cont
        add.w        #80*10,TextCursory-Space(a4)
        clr.w        TextCursorx-Space(a4)
        bra.b        .getch
.cont        sub.b        #32,d0
        move.l        TopazCharData-Space(a4),a0
        add.w        d0,a0

        add.w        TextCursorx-Space(a4),a1
        add.w        TextCursory-Space(a4),a1
        moveq        #8-1,d0
.cpy        move.b        (a0),(a1)
        add.w        #192,a0
        add.w        #80,a1
        dbra        d0,.cpy
        addq.w        #1,TextCursorx-Space(a4)
.fin        rts

Kottig_Text
        dc.b        $7f+14,'At DataStorm 2017',10,10,10
        dc.b        $7f+13,'Planet.Jazz cracked',10
        dc.b        $7f+13,'Several braincells',10
        dc.b        10,10,10
        dc.b        $7f+7,'Greetings to everyone at the party',10,10
        dc.b        $7f+4,'and heck, even to the sofa-sceners :P',10
        dc.b        10,10,10,10,10,10,10
        dc.b        'partycode, same procedure as every year james.',0
        even
Kottig_TextE

CopperData
        dc.w        $0100,$b000,$008e,$2c81,$0090,$2cc1
        dc.w        $0092,$003c,$0094,$00d4
        dc.w        $0108,$0000,$010a,$0000
        dc.w        $0102,$0407
        dc.w        $0180,$05c5,$0182,$04a4
        dc.w        $0184,$0151,$0186,$0141
        dc.w        $0188,$0fef,$018a,$0fff
        dc.w        $018c,$0fef,$018e,$0fff
CopperData_End

DosName        dc.b        'dos.library',0

TextAttr
        dc.l        0
        dc.w        8
        dc.b        0,0
TopazName
        dc.b        'topaz.font',0
        even


;                section        space,bss_c
Space
Ticks                ds.w        1
Per                ds.w        1
Vol                ds.w        1
Yptr1                ds.w        1
Yptr2                ds.w        1
Sq                ds.w        1
TextCursorx        ds.w        1
TextCursory        ds.w        1
Textptr                ds.l        1
TopazCharData        ds.l        1
TextMsg                ds.b        Kottig_TextE-Kottig_Text
Bpl_Sinus        ds.w        4096
Waveform        ds.l        1
Copper                ds.b        CopperData_End-CopperData
Bpl2                ds.w        4        ;dc.w        $00e4,$0000,$00e6,$0000
Bpl3                ds.w        4        ;dc.w        $00e8,$0000,$00ea,$0000
Bplist                ds.w        300*6        ; Triangle bitplane ptrs
                ds.l        1        ; Terminator
TextScr                ds.b        80*256
TScreen                ds.b        80*640
Space_End

EDIT
Just noticed two small inaccuracies in the copper list.
But the purpose was a bb intro example so it doesn't matter :p

D4Ni3L3 23 September 2019 21:34

Thank you so much ross! ...

Anyway I started the .adf with WinUAE and of course it works, but ... trying to figure out how things have been done ... I opened, with ASM-One, the source file you attached "pjz-its_a_sin.s" and once assembled I haven't been able to execute anything.

Can you, ... please ... , give me/us more help telling ... how to start it and how to (maybe step by step) end up writing it into and .adf disk boot block?

It would be nice to to have the file pjz-its_a_sin.adf like the one you attached.

I have greatly appreciated your work for this bb intro example ...

ross 23 September 2019 22:05

Load and assemble the source.

Then:
WS
RAM PRT>BB
DISK PTR>0
LENGTH>2
CC

What did you do in practice:
WS -> write assembled code to disk
starting from routine at BB (DC.B 'DOS',0 etc.)
at disk sector 0 (where bootblock reside)
length 2 (self explanatory :))
CC -> calculate checksum (fill the second long -> DC.L 0 with the right value)
[if you wonder what the third longword DC.L $370 is, is the disk rootblock, sector 880]

Now if you boot the disk code start from offset $c, the START label.

Enjoy!
:great

redblade 24 September 2019 12:54

http://aminet.net/package/dev/asm/Asm_course There is a Assembler course on aminet. It comes with Asm One and it comes with example code.

Read /examples/BootBlock.S

But it pretty much is as Ross says.

D4Ni3L3 24 September 2019 23:45

Quote:

Originally Posted by redblade (Post 1347470)
http://aminet.net/package/dev/asm/Asm_course There is a Assembler course on aminet. It comes with Asm One and it comes with example code.

Read /examples/BootBlock.S

But it pretty much is as Ross says.


Thanks to to ross and you too! :great

D4Ni3L3 25 September 2019 23:32

Hello... remaining in the topic of boot block tutorial, I made tonight another experiment...

Here is the code of a flashing screen waiting for the left mouse button to execute a custom boot block:

Code:


bb:
        dc.b 'DOS',0
        dc.l  0
        dc.l  $370
        dcb.b 1024,0

loop:
        move.w #$000, $dff180       
        move.w #$fff, $dff182       
 
checkExit:

        btst #6, $bfe001              ; test LEFT mouse click
        bne loop
        rts

        lea        Dos(pc),a1          ; string of dos.library into a1 register
        jsr        -96(a6)            ; call FindResident
        tst.l      d0
        beq.s      Err                ; mod.resid. not found
        movea.l    d0,a0
        movea.l    $16(a0),a0
        moveq      #0,d0
Usc:    rts
Err:    moveq      #-1,d0              ; set error flag
        bra.s      Usc

Dos:    dc.b 'dos.library',0          ; "dos.library" string

the code seems to work fine if I comment the bb part and execute in the ASM-One, but when it comes to assemble the source and follow the steps mentioned above ( WS, RAM PRT>BB, DISK PTR>0, LENGTH>2, CC ) with the purpose to write the code over a blank disk (removing the comments before bb ) nothing won't start on booting...

do you guys have any clue?

heavy 25 September 2019 23:53

what is the "dcb.b 1024,0" ?
the code is after the boot with that so not copied to disk...
loop should be just after dc.l $370

ross 25 September 2019 23:57

Code:

bb:
        dc.b 'DOS',0
        dc.l  0
        dc.l  $370
;        dcb.b 1024,0

loop:
        move.w $dff006, $dff180       
;        move.w #$fff, $dff182       
 
checkExit:

        btst #6, $bfe001              ; test LEFT mouse click
        bne loop
;        rts

        lea        Dos(pc),a1          ; string of dos.library into a1 register
        jsr        -96(a6)            ; call FindResident
        tst.l      d0
        beq.s      Err                ; mod.resid. not found
        movea.l    d0,a0
        movea.l    $16(a0),a0
        moveq      #0,d0
Usc:    rts
Err:    moveq      #-1,d0              ; set error flag
        bra.s      Usc

Dos:    dc.b 'dos.library',0          ; "dos.library" string


D4Ni3L3 26 September 2019 00:08

Quote:

Originally Posted by ross (Post 1347358)
CC -> calculate checksum (fill the second long -> DC.L 0 with the right value)
[if you wonder what the third longword DC.L $370 is, is the disk rootblock, sector 880]

Now if you boot the disk code start from offset $c, the START label.


I do not how to arrange this last step....

ross 26 September 2019 00:24

Nothing to arrange here :)
You simply need to type CC and ASM-One will generate (and write to inserted ADF, or DF0: in a real machine) the correct checksum on the disk.
Then you can boot the disk and the code in the bootblock starts.

D4Ni3L3 26 September 2019 00:36

Quote:

Originally Posted by ross (Post 1347820)

Then you can boot the disk and the code in the bootblock starts.




ross ... what I doing wrong? .... The disk just created on which I wrote the bb won't boot ... :crying

ross 26 September 2019 00:45

Quote:

Originally Posted by D4Ni3L3 (Post 1347824)

ross ... what I doing wrong? .... The disk just created on which I wrote the bb won't boot ... :crying

Did you use the version I posted? (post #16)
Notice the commented code.

I assure you that it works.


All times are GMT +2. The time now is 03:53.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.

Page generated in 0.05154 seconds with 11 queries