123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- ; $Id$
- ; MegaZeux
- ;
- ; Copyright (C) 1996 Greg Janson
- ; Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
- ;
- ; This program is free software; you can redistribute it and/or
- ; modify it under the terms of the GNU General Public License as
- ; published by the Free Software Foundation; either version 2 of
- ; the License, or (at your option) any later version.
- ;
- ; This program is distributed in the hope that it will be useful,
- ; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- ; General Public License for more details.
- ;
- ; You should have received a copy of the GNU General Public License
- ; along with this program; if not, write to the Free Software
- ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ;
- ; This file contains functions for manipulating the level arrays
- ;
- Ideal
- include "idarray.inc"
- include "data.inc"
- include "const.inc"
- p186
- JUMPS
- include "model.inc"
- Codeseg
- ;
- ; Place an id/color/param combo in an array position, moving current to
- ; "under" status if possible, and clearing original "under". If placing an
- ; "under", then automatically clear lower no matter what. Also mark as
- ; updated.
- ;
- proc id_place far
- arg array_x:word,array_y:word,id:byte,color:byte,param:byte
- local @@saved_id:byte
- push ax bx dx ds es di
- mov ax,SEG update_done
- mov ds,ax
- ;
- ; Calculate offset within arrays
- ;
- mov ax,[max_bxsiz] ; Multiply 100 by
- mul [array_y] ; Y pos,
- add ax,[array_x] ; add X pos,
- mov bx,ax ; and move into BX.
- push bx
- offset_entry:
- ; BX = Array offset
- les di,[ds:update_done] ; Mark as "updated"
- or [BYTE PTR es:di+bx],1
- les di,[ds:level_id] ; Load address of level_id in es:di
- mov bl,[es:di+bx] ; Load current id
- mov [@@saved_id],bl ; Save id
- mov di,OFFSET flags ; Load offset of flags array
- flipflag bh,bh ; Clear upper bx
- add bl,bl ; BX * 2 (id<128)
- ; BX=offset into flags array,
- ; in ds:di
- mov ax,[ds:di+bx] ; Get flags word
- pop bx ; Restore array offset
- ; AX contains flags word for id
- testflag ax,A_SPEC_STOOD
- jnz @@sensor
- and ax,A_UNDER ; Can id "go under"?
- jz @@no_under ; No...
- ; Get flags for id being PLACED.
- push bx
- mov bl,[id]
- add bl,bl
- flipflag bh,bh
- mov ax,[ds:di+bx]
- pop bx
- testflag ax,A_UNDER
- jnz @@no_under ; If placing an UNDER, then ERASE
- ; current under.
- ; Yes. Move id/param/color to
- ; "under"
- @@under_ok:
- cmp [id],127
- jne @@under_ok_normal
- ; Save double under
- mov al,[@@saved_id] ; Load id
- les di,[ds:level_under_id] ; Load location of under_id's
- xchg [es:di+bx],al ; Save id in "under"
- mov [under_player_id],al
- les di,[ds:level_param]
- mov al,[es:di+bx] ; Load param
- les di,[ds:level_under_param]
- xchg [es:di+bx],al ; Save param in "under"
- mov [under_player_param],al
- les di,[ds:level_color]
- mov al,[es:di+bx] ; Load color
- les di,[ds:level_under_color]
- xchg [es:di+bx],al ; Save color in "under"
- mov [under_player_color],al
- jmp @@under_done ; Skip @@no_under part
- @@under_ok_normal:
- mov al,[@@saved_id] ; Load id
- les di,[ds:level_under_id] ; Load location of under_id's
- mov [es:di+bx],al ; Save id in "under"
- les di,[ds:level_param]
- mov al,[es:di+bx] ; Load param
- les di,[ds:level_under_param]
- mov [es:di+bx],al ; Save param in "under"
- les di,[ds:level_color]
- mov al,[es:di+bx] ; Load color
- les di,[ds:level_under_color]
- mov [es:di+bx],al ; Save color in "under"
- jmp @@under_done ; Skip @@no_under part
- @@sensor:
- cmp [id],127
- jne @@no_under
- ; Player -> sensor = ok
- jmp @@under_ok
- @@no_under:
- les di,[ds:level_under_id] ; Load location of under_id's
- ; al=0 'cause of prev. and
- xor al,al
- mov [es:di+bx],al ; Clear "under" id
- les di,[ds:level_under_param]
- mov [es:di+bx],al ; Clear "under" param
- les di,[ds:level_under_color]
- mov [BYTE PTR es:di+bx],7 ; Clear "under" color
- @@under_done:
- les di,[ds:level_id]
- mov al,[id]
- mov [es:di+bx],al ; Store new id
- les di,[ds:level_color]
- mov al,[color]
- mov [es:di+bx],al ; Store new color
- les di,[ds:level_param]
- mov al,[param]
- mov [es:di+bx],al ; Store new param
- pop di es ds dx bx ax
- ret
- endp id_place
- ; "blank" is just that- irrevelant and usually blank.
- proc offs_place_id far
- arg offs:word,junk:word,id:byte,color:byte,param:byte
- push ax bx dx ds es di
- ;
- ; Calculate offset within arrays, jump within above function
- ;
- mov ax,SEG update_done
- mov ds,ax
- mov bx,[offs]
- push bx
- jmp offset_entry
- endp offs_place_id
- proc id_place_asm near
- arg array_x:word,array_y:word,id_color:word,param:byte
- local @@saved_id:byte
- push ax bx cx dx es di
- mov ax,SEG level_id
- mov ds,ax
- ;
- ; Calculate offset within arrays
- ;
- mov bx,[array_y]
- mov ax,[max_bxsiz] ; Multiply 100 by
- mul bx ; Y pos,
- add ax,[array_x]
- mov bx,ax
- mov cx,bx
- ;
- ; BX = Array offset
- ;
- les di,[ds:update_done] ; Mark as "updated"
- or [BYTE PTR es:di+bx],1
- les di,[ds:level_id] ; Load address of level_id in es:di
- mov bl,[es:di+bx] ; Load current id
- mov [@@saved_id],bl ; Save id
- mov di,OFFSET flags ; Load offset of flags array
- xor bh,bh ; Clear upper bx
- add bl,bl ; BX * 2 (id<128)
- ;
- ; BX=offset into flags array, in ds:di
- ;
- mov ax,[ds:di+bx] ; Get flags word
- mov bx,cx ; Restore array offset
- ; AX contains flags word for id
- testflag ax,A_SPEC_STOOD
- jnz @@sensor
- and ax,A_UNDER ; Can id "go under"?
- jz @@no_under ; No...
- ; Get flags for id being PLACED.
- ;
- mov bl,[BYTE LOW id_color]
- add bl,bl
- xor bh,bh
- mov ax,[ds:di+bx]
- mov bx,cx
- testflag ax,A_UNDER
- jnz @@no_under ; If placing an UNDER, then ERASE current under.
- ;
- ; Yes. Move id/param/color to "under"
- ;
- @@under_ok:
- cmp [BYTE PTR id_color],127
- jne @@under_ok_normal
- ; Save double under
- mov al,[@@saved_id] ; Load id
- les di,[ds:level_under_id] ; Load location of under_id's
- xchg [es:di+bx],al ; Save id in "under"
- mov [under_player_id],al
- les di,[ds:level_param]
- mov al,[es:di+bx] ; Load param
- les di,[ds:level_under_param]
- xchg [es:di+bx],al ; Save param in "under"
- mov [under_player_param],al
- les di,[ds:level_color]
- mov al,[es:di+bx] ; Load color
- les di,[ds:level_under_color]
- xchg [es:di+bx],al ; Save color in "under"
- mov [under_player_color],al
- jmp @@under_done ; Skip @@no_under part
- @@under_ok_normal:
- mov al,[@@saved_id] ; Load id
- les di,[ds:level_under_id] ; Load location of under_id's
- mov [es:di+bx],al ; Save id in "under"
- les di,[ds:level_param]
- mov al,[es:di+bx] ; Load param
- les di,[ds:level_under_param]
- mov [es:di+bx],al ; Save param in "under"
- les di,[ds:level_color]
- mov al,[es:di+bx] ; Load color
- les di,[ds:level_under_color]
- mov [es:di+bx],al ; Save color in "under"
- jmp @@under_done ; Skip @@no_under part
- @@sensor:
- cmp [BYTE PTR id_color],127
- jne @@no_under
- ; Player -> sensor = ok
- jmp @@under_ok
- @@no_under:
- les di,[ds:level_under_id] ; Load location of under_id's
- mov [BYTE PTR es:di+bx],0 ; Clear "under" id
- les di,[ds:level_under_param]
- mov [BYTE PTR es:di+bx],0 ; Clear "under" param
- les di,[ds:level_under_color]
- mov [BYTE PTR es:di+bx],7 ; Clear "under" color
- @@under_done:
- les di,[ds:level_id]
- mov ax,[id_color]
- mov [es:di+bx],al ; Store new id
- les di,[ds:level_color]
- mov [es:di+bx],ah ; Store new color
- les di,[ds:level_param]
- mov al,[param]
- mov [es:di+bx],al ; Store new param
- pop di es dx cx bx ax
- ret
- endp id_place_asm
- ;
- ; Clears (both main and "under") an id in array position given by parameters.
- ;
- proc id_clear
- arg array_x:word,array_y:word
- push ax bx dx es ds di
- mov ax,SEG level_id
- mov ds,ax
- ;
- ; Calculate offset within arrays
- ;
- mov ax,[max_bxsiz] ; Multiply 100 by
- mul [array_y] ; Y pos,
- add ax,[array_x] ; add X pos,
- mov bx,ax ; and move into BX.
- les di,[ds:level_id] ; Load address of level_id in es:di
- xor al,al
- ;
- ; BX = Array offset ES:DI = Level Id DS: = Near segment
- ;
- mov [BYTE PTR es:di+bx],al ; Clear ID
- les di,[ds:level_param]
- mov [BYTE PTR es:di+bx],al ; Clear param
- les di,[ds:level_under_id]
- mov [BYTE PTR es:di+bx],al ; Clear under id
- les di,[ds:level_under_param]
- mov [BYTE PTR es:di+bx],al ; Clear under param
- les di,[ds:level_color]
- mov [BYTE PTR es:di+bx],7 ; Clear color (grey)
- les di,[ds:level_under_color]
- mov [BYTE PTR es:di+bx],7 ; Clear under color (grey)
- les di,[ds:update_done]
- or [BYTE PTR es:di+bx],1 ; Mark as updated
- pop di ds es dx bx ax
- ret
- endp id_clear
- ;
- ; Removes the top at the given array position, moving any "under" up.
- ;
- proc id_remove_top
- arg array_x:word,array_y:word
- push ax bx dx es ds di
- mov ax,SEG level_id
- mov ds,ax
- ;
- ; Calculate offset within arrays
- ;
- mov ax,[max_bxsiz] ; Multiply 100 by
- mul [array_y] ; Y pos,
- add ax,[array_x] ; add X pos,
- mov bx,ax ; and move into BX.
- offset_enter_remid:
- ;
- ; BX = Array offset ES:DI = Level Under Id DS: = Near segment
- ;
- les di,[ds:level_id]
- cmp [BYTE PTR es:di+bx],127
- jne @@normal_clear
- les di,[ds:level_under_id] ; Load seg:offs of level_under_id
- xor al,al
- xchg al,[under_player_id]
- xchg al,[es:di+bx] ; Load under id
- les di,[ds:level_id]
- mov [BYTE PTR es:di+bx],al ; Save in normal position
- les di,[ds:level_under_param]
- xor al,al
- xchg al,[under_player_param]
- xchg al,[es:di+bx] ; Load under param
- les di,[ds:level_param]
- mov [BYTE PTR es:di+bx],al ; Save in normal position
- les di,[ds:level_under_color]
- mov al,7
- xchg al,[under_player_color]
- xchg al,[es:di+bx] ; Load under color
- les di,[ds:level_color]
- mov [BYTE PTR es:di+bx],al ; Save in normal position
- jmp @@thingydone
- @@normal_clear:
- les di,[ds:level_under_id] ; Load seg:offs of level_under_id
- mov al,[es:di+bx] ; Load under id
- mov [BYTE PTR es:di+bx],0 ; then clear it
- les di,[ds:level_id]
- mov [BYTE PTR es:di+bx],al ; Save in normal position
- les di,[ds:level_under_param]
- mov al,[es:di+bx] ; Load under param
- mov [BYTE PTR es:di+bx],0 ; then clear it
- les di,[ds:level_param]
- mov [BYTE PTR es:di+bx],al ; Save in normal position
- les di,[ds:level_under_color]
- mov al,[es:di+bx] ; Load under color
- mov [BYTE PTR es:di+bx],7 ; then clear it (with grey)
- les di,[ds:level_color]
- mov [BYTE PTR es:di+bx],al ; Save in normal position
- @@thingydone:
- les di,[ds:update_done]
- or [BYTE PTR es:di+bx],1 ; Mark as done
- pop di ds es dx bx ax
- ret
- endp id_remove_top
- ; "blank" is a junk word
- proc offs_remove_id far
- arg offs:word,blank:word
- push ax bx dx es ds di
- ;
- ; Calculate offset within arrays and jump to within above
- ;
- mov ax,SEG level_id
- mov ds,ax
- mov bx,[offs]
- jmp offset_enter_remid
- endp offs_remove_id
- ;
- ; Removes any "under" from the given array position
- ;
- proc id_remove_under
- arg array_x:word,array_y:word
- push ax bx dx es ds di
- mov ax,SEG level_id
- mov ds,ax
- ;
- ; Calculate offset within arrays
- ;
- mov ax,[max_bxsiz] ; Multiply 100 by
- mul [array_y] ; Y pos,
- add ax,[array_x] ; add X pos,
- mov bx,ax ; and move into BX.
- les di,[ds:level_under_id]
- xor al,al
- ;
- ; BX = Array offset ES:DI = Level Under Id DS: = Near segment
- ;
- mov [BYTE PTR es:di+bx],al ; Clear under id
- les di,[ds:level_under_param]
- mov [BYTE PTR es:di+bx],al ; Clear under param
- les di,[ds:level_under_color]
- mov [BYTE PTR es:di+bx],7 ; Clear under color (grey)
- les di,[ds:update_done]
- or [BYTE PTR es:di+bx],1 ; Mark as done
- pop di ds es dx bx ax
- ret
- endp id_remove_under
- ends
- end
|