ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
;             *** Level editor to Bolder Dash ***
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
;
;  Just for internal use...
;  Code is a totaly mess, but who cares
;  
;   (C) Copyright 1996  Suicide Software  All Rights Reserved.
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ


        IDEAL
        P386N


ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
; *** Equates ***
   
_Delay          =       2
Key_Up          =       27h
Key_Down        =       34h
Key_Left        =       2Ch
Key_Right       =       2Dh

LF              =       10
CR              =       13
EOS             =       '$'
Icon_Res        =       12
Icon_Size       =       12*12
Num_Icons       =       29
Page_1          =       X_Byte*12
Page_2          =       Page_Size + X_Byte*12
Icon_Offset     =       Page_Size*2



; *** Macros ***
Macro   IODELAY
        jmp     short $+2               ; Short delay between I/O
        jmp     short $+2               ; to same device
EndM    IODELAY


INCLUDE         "BDE.INC"
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ


ASSUME  CS:Code_Seg, SS:Stack_Seg


SEGMENT Code_Seg        Para    Public          'CODE'          USE16
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
Start:  mov     ax,Data_Seg             ; DS = GS = Data Seg
        mov     ds,ax
        mov     gs,ax
        cld


; Clear data
        mov     di,Offset Clear_Offset
        mov     cx,Clear_Size
        xor     al,al
@@00:   mov     [Byte ds:di],al
        inc     di
        loop    @@00


; Get allocated memory
        mov     ah,4Ah
        mov     bx,0FFFFh
        int     21h                     ; BX = Free mem
        mov     [Word ds:Free_Mem],bx


; Write init message
        mov     ah,09h
        mov     dx,Offset Init_Str
        int     21h


; Get param string
        call    Get_Param
        or      bx,bx
        jnz     @@10
        mov     dx,Offset Param_Err     ; No file name...
        call    Exit_Write

@@10:   mov     bp,bx                   ; BP = Param count
        mov     cx,1                    ; Get File name
        call    One_Param
        push    si                      ; Save it
        dec     bp
        jz      @@20                    ; No more more params

        mov     cx,2
        call    One_Param
        cmp     [Byte ds:si],'/'        ; Is it a switch?
        jne     Error2

        mov     ax,[Word ds:si+1]       ; Get switch
        cmp     ax,':L'                 ; Level switch?
        jne     @@15

        mov     di,si                   ; Convert number to bin
        add     di,3
        call    ASCII_To_Bin
        jc      Error2
        mov     [Word ds:Level_Num],ax  ; Save it
        dec     bp                      ; No more params
        jz      @@20

        mov     cx,3
        call    One_Param
        cmp     [Byte ds:si],'/'        ; Is it a switch?
        jne     Error2
        mov     al,[Byte ds:si+1]       ; Get switch


; Check next switch
@@15:   cmp     al,'X'                  ; Edit info?
        jne     @@20
        mov     [Byte ds:Edit_Info],1   ; Set flag


; Init registers
@@20:   xor     ax,ax                   ; FS = 0
        mov     fs,ax
        xor     esi,esi
        xor     edi,edi


; Get level segment
        mov     ax,Stack_Seg
        add     ax,(64*2) / 16
        mov     [Word ds:Level_Seg],ax


; Open/Create file
        pop     si                      ; SI = File name
        mov     ax,06C00h
        mov     bl,2                    ; R/W accses
        mov     bh,00100000b
        xor     cx,cx
        mov     dx,00010001b
        int     21h
        jc      Error2
        mov     [Word ds:File_Handle],ax

        cmp     cx,1                    ; Opend?
        je      @@50


; File is created, so setup!
        call    New_Level
        jc      Error2
        jmp     N_Edit                  ; Buffer is already setup


; Load level file
@@50:   mov     ax,[Word ds:Level_Seg]
        mov     bx,[Word ds:File_Handle]
        call    Load_File
        jc      Error2
        mov     [Word ds:File_Size],cx

        call    Copy_Header

        cmp     [Byte ds:Edit_Info],0   ; Shall we edit info?
        je      G_Edit                  ; No, jump


; *** Normal edit ***
N_Edit: call    Edit_Header
        jc      Error2


; Copy header into level buffer
        mov     ax,[Word ds:Level_Seg]  ; ES = Level seg
        mov     es,ax
        mov     bx,[Word ds:Level_Num]
        add     bx,bx
        mov     dx,[Word es:4+bx]       ; AX = Para offset to current level
        mov     ax,[Word ds:Level_Seg]
        add     ax,dx
        mov     es,ax
        xor     di,di                   ; ES:DI = Where to copy

        mov     si,Offset _H            ; Copy header
        mov     cx,23
        rep     movsb

        cmp     [Byte ds:Edit_Info],1
        je      Save_F

; *** Graphic edit ***
G_Edit: call    Setup_Int
        call    ModeX
        call    Init

        call    Edit_Level
        or      al,al
        jns     Save_F

        cmp     al,-2           ; Editing my level?
        jne     Error

        mov     ax,03h          ; Clean up and exit with error message
        int     10h
        call    Exit_Stuff
        mov     dx,Offset Shame_Str
        jmp     Exit_Write


; *** Finished, so save the file ***
Save_F: cmp     [Byte ds:ESC_Flagg],2   ; Don't save?
        je      Exit
        mov     si,Offset Save_Str      ; Write save message
        call    Str_Write
        call    Copy_Level              ; Copy current map to level buffer
        mov     ax,[Word ds:Level_Seg]
        mov     bx,[Word ds:File_Handle]
        mov     bp,[Word ds:File_Size]
        call    Save_File
        jc      Error


ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
; Clean up and exit
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
Exit:   cmp     [Byte ds:Edit_Info],0   ; Skipp of no graphical edit
        jne     Exit2
        call    Exit_Stuff
        mov     ax,0003h
        int     10h
        cmp     [Byte ds:ESC_Flagg],2   ; Save?
        je      Exit2
        mov     si,Offset Save_Str      ; Write save message
        call    Str_Write

Exit2:  mov     ax,04C00h
        int     21h



ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
; Somthing screwed up :(
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
Error:  mov     ax,03h
        int     10h
        call    Exit_Stuff

Error2: mov     dx,Offset Error_Str     ; Don't reset

Exit_Write:
        mov     ah,09h
        int     21h
        

; If file is created but have size=0, delete it!
        mov     ah,042h                 ; Get file size
        mov     al,2
        mov     bx,[Word ds:File_Handle]
        xor     cx,cx
        xor     dx,dx
        int     21h
        jc      _Exit                   ; If file is closed, then it's ok!

        or      ax,ax                   ; Check size
        jnz     _Exit
        or      dx,dx
        jnz     _Exit

        mov     ah,3Eh                  ; Close file        
        int     21h
        mov     ah,041h                 ; Delete file
        mov     dx,Offset Param_Str
        int     21h

_Exit:  mov     ax,04CFFh
        int     21h


INCLUDE         "EDIT.INC"
INCLUDE         "INTERUPT.INC"
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
EndS    Code_Seg




SEGMENT Data_Seg        Para    Public          'DATA'          USE16
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
INCLUDE         "PAL.INC"               ; The palette
INCLUDE         "GRAPHICS.INC"          ; The graphics/icons


; *** Messages ***
Init_Str        db      CR,LF,'BD Level editor v1.0 - (c) 96 Suicide Software'
                db      CR,LF,'ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ',CR,LF,EOS
Param_Err       db      CR,LF,'You must provide a file name, dude...',CR,LF,EOS
File1_Str       db      ' Don''t exist! Creating it now...',0
Error_Str       db      CR,LF,LF,'ERROR: Somthing screwed up!',CR,LF,EOS
Mouse_Str       db      CR,LF,'Sorry, you ned a mouse (driver) to run this!',CR,LF,EOS
Save_Str        db      CR,LF,LF,'Saving level... Done!',CR,LF,0
Shame_Str       db      CR,LF,'That''s called cheting! You''re not suposed to edit this level. Shame on you! :)',CR,LF,EOS

Str1            db      CR,LF,'X Size (30 - 100)        : ',0
Str2            db      CR,LF,'Y Size (19 - 100)        : ',0
Str3            db      CR,LF,'Filler (0/1)             : ',0
Str4            db      CR,LF,'Time (',0
Str5            db      CR,LF,'Dimonds to take (',0
Str6            db      CR,LF,'Dimond score 1 (',0
Str7            db      CR,LF,'Dimond score 2 (',0
Str8            db      CR,LF,'Magic wall time (',0
Str9            db      CR,LF,'Start position X (',0
Str10           db      CR,LF,'Start position Y (',0
Str11           db      CR,LF,'Bonus life (0=No) (',0
Str12           db      CR,LF,'Level name : ',0
Str_End         db      ') : ',0


; *** Lockup tables ***
Label   Icon_Table      Word            ; Offsets to icons

I = Icon_Offset

Rept    Num_Icons
 dw     I
 I=I+(Icon_Size/4)
EndM


Type_Table      db      01,06,09,03,12,15,07,04,21,02,20        ; 11 items


; *** Data ***
Delay           db      _Delay


        ALIGN   DWORD

; *** Data (Must be cleared) ***
LABEL           Clear_Offset
Map_Size        dw      ?               ; H * V
Level_Num       dw      ?
Map_H           db      ?
Map_V           db      ?
Pos_H           db      ?
Pos_V           db      ?
Frame1          db      ?               ; 2 Normal
Frame2          db      ?               ; 3 Normal
Frame3          db      ?               ; 2 Slow (0 - 3)
Frame4          db      ?               ; 2 Fast
Update          db      ?               ; Time to update screen
Curr_Page       db      ?
Draw_Type       db      ?               ; Item to draw
Edit_Info       db      ?               ; 1 = Yes
ESC_Flagg       db      ?               ; 1 = Yes, 2 = Don't save
Key_Map         db      128 Dup (?)
Input_Str       db      15+1 Dup(?)


; *** Info header ***
_H              db      ?
_V              db      ?
_Time           db      ?
_Dimond         db      ?
_Dimond1        db      ?
_Dimond2        db      ?
_Magic          db      ?
_StartH         db      ?
_StartV         db      ?
_Bonus          db      ?
_Name           db      13 Dup(?)
Clear_Size      =       $ - Clear_Offset



; *** Uninstaled data ***
Int_09h         dd      ?
Level_Seg       dw      ?
File_Handle     dw      ?
File_Size       dw      ?
Free_Mem        dw      ?
Filler          db      ?
Param_Str       db      128+1 Dup(?)
Map             db      100*100 + 4 Dup(?)      ; Temp map
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
EndS    Data_Seg



ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
SEGMENT Stack_Seg       Para    Stack           'STACK'         USE16
        dw      64 Dup (?)      ; A 64 words stack
EndS    Stack_Seg
ﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄﾄ
        End     Start
