#if 0 Notes to self: Possible optimzing points: getoffset buyunit_finish everywhere Jump locations: FindMap #endif ;---------------------------------------------------------------------------------------Quick Jump to names #include "ti86asm.inc" .org _asm_exec_ram nop jp Start .dw 0 .dw ShellTitle ShellTitle: .db "Total Conquest v0.3",0 Start: ;----------------------------------------------------------------------------------------Preparation ld (spointer),sp call $4AB1 ;Turn off the run-indicator res appTextSave,(IY+appflags) ;Stop saving _textShadow so it isn't redrawn set 1,(iy+5) ;Clears the bottom line off of text ;----------------------------------------------------------------------------------------Equates #define inverse set 3,(iy+5) #define normal res 3,(iy+5) #define cursor_x cursor_xy+1 #define cursor_y cursor_xy #define temp_space _textShadow #define more_temp_space $ca00 VideoRam = $ca00 VideoRam2 = $fc00 Version = ShellTitle+14 old_cursor_xy = temp_space+2 cursor_moved = temp_space+4 upper_range = temp_space+6 lower_range = temp_space+7 left_range = temp_space+8 right_range = temp_space+9 should_stats_be_moved_down = temp_space+20 display_name_only = temp_space+22 display_stat_text_at = temp_space+24 display_stat_sprites_at = temp_space+26 display_stats = temp_space+28 player_cash_when_buying = temp_space+30 unit_cost = temp_space+32 action_unit_value = temp_space+34 unit_totalhp = temp_space+36 unit_totalpower = temp_space+38 unit_range = temp_space+40 is_this_a_missilesilo = temp_space+42 display_doable_action = temp_space+44 unit_action = temp_space+46 explosion_damage = temp_space+48 firing_projectile = temp_space+50 placing_unit = temp_space+52 allow_turn_skipping = temp_space+54 allow_help = temp_space+56 sprite_address = temp_space+102 unit_cell_value = temp_space+104 buy_menu_address = temp_space+106 temp_address_1 = temp_space+110 temp_address_2 = temp_space+112 temp_address_3 = temp_space+114 temp_address_4 = temp_space+116 temp_address_5 = temp_space+118 temp_address_6 = temp_space+120 temp_address_7 = temp_space+122 idle_counter = temp_space+126 mapname = temp_space+140 temp = temp_space+150 MainMenu: ld hl,title_screen ld de,VideoRam2 call DispRLE ld hl,Version ld bc,$0000 ld (_penCol),bc call _vputs xor a \ ld (temp_address_1),a mainmenu_display: ld hl,text_mainmenu ld d,64 ld e,0 \ ld b,33 \ call checkifhighlighted ld e,1 \ ld b,41 \ call checkifhighlighted ld e,2 \ ld b,49 \ call checkifhighlighted ld e,3 \ ld b,57 \ call checkifhighlighted mainmenu_waitforkey: call Slow call _getky cp K_DOWN \ jr z,mainmenu_down cp K_UP \ jr z,mainmenu_up cp K_SECOND \ jr z,mainmenu_check cp K_EXIT \ jp z,quit_1 jr mainmenu_waitforkey mainmenu_down: ld hl,temp_address_1 \ ld a,3 \ cp (hl) \ jr z,mainmenu_display \ inc (hl) jr mainmenu_display mainmenu_up: ld hl,temp_address_1 \ xor a \ cp (hl) \ jr z,mainmenu_display \ dec (hl) jr mainmenu_display mainmenu_check: ld a,(temp_address_1) cp 2 \ jp z,resumegame cp 1 \ jp z,FindMap and a \ jp nz,quit_1 newgame_1: jp options newgame: ld hl,data_start \ ld (hl),0 ld de,data_start+1 ld bc,data_end-data_start ldir ld a,1 ld (player_banks+1),a ld (player_banks),a inc a ld (current_player),a ld a,100 AmountOfStartingCash = $-1 ld (player_money+1),a ld (player_money),a ;----------------------------------------------------------------------------------------Field preparation ld hl,units+13 \ ld (hl),%01010000 ld hl,health+13 \ ld (hl),100 ld hl,power+13 \ ld (hl),0 ld hl,units+130 \ ld (hl),%10010000 ld hl,health+130 \ ld (hl),100 ld hl,power+130 \ ld (hl),0 xor a ld b,10 AmountOfMountains = $-1 cp b \ jr z,landdone RandomizeLandLoop: push bc call placerandomland pop bc djnz RandomizeLandLoop landdone: xor a ld b,10 AmountOfResources = $-1 cp b \ jr z,resourcesdone RandomizeRockLoop: push bc call placerandomrock pop bc djnz RandomizeRockLoop resourcesdone: ;----------------------------------------------------------------------------------------Screen preparation ScreenPreparation: call RedrawScreen call OpenGray ;Turn the grayscale on ;----------------------------------------------------------------------------------------Turn routine ld bc,$0202 ;Set the cursor to be at 1,1 ld (cursor_xy),bc ;Load it in Newturn: ld a,(current_player) ;Changes the player xor 3 ld (current_player),a call clearstatarea sentrytowerfire: ld a,143 sentrytowerfire_1: ld (temp_address_1),a ld hl,units call AddAtoHL ld a,(hl) ld (temp_address_2),a call GetUnitValue cp 14 \ jp nz,sentrytower_skip ld a,(temp_address_2) call GetOwnerValue ld hl,current_player cp (hl) \ jp nz,sentrytower_skip ld hl,text_towersfiring ld b,2 ld de,$0941 call DisplayTextArray ld a,(temp_address_1) ;DECREASE THE TOWER COORDS BY 13 TO GET THE UPPER LEFT sub 12 ld (temp_address_3),a call sentrytower_handlerow call sentrytower_handlenextrows sentrytower_skip: ld a,(temp_address_1) dec a and a \ jp nz,sentrytowerfire_1 ld a,3 ;Allows the player 3 actions ld (time_left),a ld hl,player_banks-1 ld a,(current_player) call AddAtoHL ld b,(hl) ;b contains the player's number of banks push bc ld b,5 call PRandom ld e,a ld d,0 ;de contains a random cash amount for each bank pop bc call Multiply ;hl now contains the cash bonus push hl ld hl,player_money-1 ld a,(current_player) call AddAtoHL ld a,(hl) ;a contains the player's cash ex de,hl ;de contains the right part of memory pop hl add a,l call c,TooMuchCash ex de,hl ld (hl),a call DrawField call DrawStatBox call ResetSpecials Turn: ld a,1 \ ld (allow_turn_skipping),a ld b,12 call SetRanges call Cursor ;Returns a with a value 255 to exit cp 100 \ jp z,Newturn cp 255 \ jp nz,Action Quit: ;writeback by Jonah Cohen ld hl,save_name-1 rst 20h rst 10h call nc,_delvar ld hl,data_end-data_start call $472f call _ex_ahl_bde call _ahl_plus_2_pg3 call _set_abs_dest_addr sub a ld hl,data_start call _set_abs_src_addr sub a ld hl,data_end-data_start call _mm_ldir_set_size quit_1: call CloseGray ld sp,(spointer) res 1,(iy+5) set appTextSave,(IY+appflags) ;Allow _textShadow to be used set graphdraw,(IY+graphflags) ;"Clear" the PlotScreen call _clrScrn ;Clear the screen and _textShadow buffer jp _homeup ;Set the x,y to 1,1 completedaction: call DrawField ld hl,units+13 \ xor a \ cp (hl) \ jp z,Lose ld hl,units+130 \ xor a \ cp (hl) \ jp z,Lose ld hl,time_left dec (hl) xor a cp (hl) \ jp z,Newturn call DrawStatBox incompleteaction: call ResetSpecials jr Turn ;----------------------------------------------------------------------------------------Sub-sub routines for the above checkifhighlighted: ld a,(temp_address_1) cp e jp nz,vputs_center_1 inverse call vputs_center_1 normal ret sentrytower_handlenextrows: call sentrytower_nextrow sentrytower_nextrow: ld a,(temp_address_3) add a,11 ld (temp_address_3),a sentrytower_handlerow: ld hl,temp_address_3 \ dec (hl) \ call sentrytower_dealwithunit ld hl,temp_address_3 \ inc (hl) \ call sentrytower_dealwithunit ld hl,temp_address_3 \ inc (hl) sentrytower_dealwithunit: ld a,(temp_address_3) ld hl,units call AddAtoHL ld a,(hl) call GetOwnerValue ld hl,current_player cp (hl) \ ret z and a \ ret z ld a,(temp_address_3) ld hl,health call AddAtoHL ld a,(hl) sub 10 jr c,sentrytower_killedunit jr z,sentrytower_killedunit ld (hl),a ld bc,$2f41 ld (_penCol),bc ld hl,text_units call _vputs ld hl,text_hit call _vputs ret sentrytower_killedunit: ld a,(temp_address_3) ld hl,units call AddAtoHL ld a,(hl) call GetUnitValue ld (hl),0 ld bc,$3541 ld (_penCol),bc ld hl,text_units call _vputs ld hl,text_destroyed call _vputs ret FindMap: ld hl,$bfff \ ld (mapaddress),hl findmap_1: ld a,$0c ld hl,$bfff mapaddress = $-2 call vatsrch ;search starting at hl for external map jp c,MainMenu ;if set, they don't exist ld (mapaddress),hl ld de,_OP1 ;where we want to store the name at call copy_to_op1 ;copy backwards vat name to op1 the right way ex de,hl ;put it into hl ld de,mapname ;the target location call _mov10b ;copies 10 bytes over to the mapname variable loadmap: ld hl,mapname-1 rst 20h ;copy to OP1 rst 10h ;_findsym call _ex_ahl_bde call _inc_ptr_ahl call loadmap_1 jr nz,findmap_1 call loadmap_1 jr nz,findmap_1 call _inc_ptr_ahl push af push hl call _clrLCD ;checks to see if this is the level they want ld bc,0 ld (_penCol),bc ld hl,text_thisone call _vputs ld hl,mapname ld b,(hl) inc hl call _vputsn loadmap_check: call _getkey cp k9 \ jr z,findmap_1 cp k0 \ jr nz,loadmap_check pop hl pop af call _set_abs_src_addr xor a ;no absolute addressing now ld hl,data_start ;put data here call _set_abs_dest_addr xor a ld hl,majordata-data_start ;number of bytes to save call _mm_ldir_set_size ;copy data ld hl,m_start ld de,majordata ld bc,m_end-m_start ldir jr resume_1 loadmap_1: call _inc_ptr_ahl ld c,a push hl call _getb_ahl cp $16 ; Check header bytes pop hl ld a,c ret resumegame: ld hl,save_name-1 ; rst 20h ;copy 10 bytes from hl to op1 rst 10h jp c, MainMenu call _ex_ahl_bde call _ahl_plus_2_pg3 call _set_abs_src_addr sub a ld hl,data_start call _set_abs_dest_addr xor a ld hl,data_end-data_start ;length of data call _mm_ldir_set_size ;copy data and return resume_1: call RedrawScreen call OpenGray jp Turn ResetSpecials: xor a \ ld (display_doable_action),a ld (display_name_only),a ld (should_stats_be_moved_down),a ld (firing_projectile),a ;NEVER SEPARATE THESE 7 LINES ld (placing_unit),a inc a \ ld (display_stats),a ld (allow_turn_skipping),a ld (allow_help),a ret placerandomrock: call getrandomcoordinate ld de,units add hl,de xor a cp (hl) \ jr nz,placerandomrock ld (hl),27 ret placerandomland: call getrandomcoordinate ld de,land add hl,de ld a,2 cp (hl) \ jr z,placerandomland ld (hl),2 ld de,13 sbc hl,de call lowlandrow call movedownfirst movedownfirst: ld de,10 add hl,de lowlandrow: call checkforhighlands inc hl call checkforhighlands inc hl checkforhighlands: ld a,2 cp (hl) \ ret z ld (hl),1 ret getrandomcoordinate: ld b,10 call PRandom inc a ld d,0 ld e,a push de call Slow ld b,10 call PRandom inc a ld b,a ld de,12 call Multiply ex de,hl pop hl add hl,de ret ;------------------------------------------------------------------------------------------------------------------ ;----------------------------------------------------------------------------------------Begin subroutine section-- ;------------------------------------------------------------------------------------------------------------------ Lose: call clearstatarea call DrawField ld hl,text_gameover ld de,$0941 ld b,2 call DisplayTextArray ld a,(current_player) call displaya ld hl,text_gameover_1 call _vputs lose_1: ld a,%10111111 ;Set which row to check out (1),a ;Send it in a,(1) ;Get results bit 6,a \ jp z,Quit jr lose_1 ;----------------------------------------------------------------------------------------Actions Action: ld a,1 \ ld (display_name_only),a call Stats xor a \ ld (display_stats),a ld (allow_turn_skipping),a ;NEVER SEPARATE THESE LINES ld (allow_help),a inc a \ ld (should_stats_be_moved_down),a call getoffset ld hl,units call GetCell ld (temp_address_1),a ;Contains the value of the cell and a \ jp z,error_nothingthere call GetOwnerValue ld hl,current_player cp (hl) \ jp nz,error_notyours ld a,(temp_address_1) call GetUnitValue ld (action_unit_value),a cp 14 \ jp z,error_notusable jp nc,stationaryunitactions moveableunitactions: push af xor a \ ld (display_name_only),a inc a \ ld (display_stats),a pop af ld hl,baserange-1 call AddAtoHL ld b,(hl) ;b contains the range for that unit call SetRanges ;Sets the ranges call getoffset ld (temp_address_1),de ;temp_address_1 contains the offset for the old cursor value ld hl,(cursor_xy) ld (old_cursor_xy),hl ld a,1 \ ld (display_doable_action),a call cursor_display_1 call Cursor cp 255 \ jp z,error_actioncancelled ld a,(unit_action) and a \ jp z,error_actioncancelled cp 1 \ jp z,move cp 2 \ jp z,attack cp 3 \ jp z,heal cp 4 \ jp z,harvest cp 6 \ jp z,boom push af call clearlowerstatarea pop af jp stationaryunitactions heal: ld de,(temp_address_7) ld hl,health call GetCell ld b,3 add a,b ld (hl),a jp completedaction attack: ld b,255 call PRandom cp 100 \ jp c,attack_missed ld de,(temp_address_7) ld hl,health call GetCell push hl push af ld de,(temp_address_7) ld hl,land call GetCell ld b,a pop af add a,b push af ld de,(temp_address_1) ld hl,power call GetCell push af ld de,(temp_address_1) ld hl,land call GetCell ld b,a pop af add a,b ld b,a pop af pop hl sub b jr z,attack_fatal jr c,attack_fatal ld (hl),a ld hl,text_hit jr action_display_result attack_fatal: ld de,(temp_address_7) ld hl,units call GetCell ld (hl),0 ld hl,text_destroyed jr action_display_result attack_missed: ld hl,text_missed action_display_result: push hl call clearlowerstatarea ld hl,text_unit ld bc,$1141 ld (_penCol),bc call _vputs pop hl call _vputs jp completedaction harvest: ld de,(temp_address_7) ld hl,units call GetCell ld (hl),0 call placerandomrock ld hl,player_money-1 ld a,(current_player) call AddAtoHL ld a,(hl) ld b,25 add a,b call c,TooMuchCash ld (hl),a call clearlowerstatarea ld hl,text_harvested ld bc,$1141 ld (_penCol),bc call _vputs jp completedaction boom: ld de,(temp_address_7) push de call clearlowerstatarea ld hl,text_mine ld bc,$1141 ld (_penCol),bc call _vputs ld a,15 \ ld (explosion_damage),a call Explosion pop de ld hl,units call GetCell ld (hl),0 jp completedaction move: ld de,(temp_address_1) push de push de ld hl,units call GetCell ld (action_unit_value),a ld (hl),0 ld de,(temp_address_7) ld hl,units call GetCell ld a,(action_unit_value) ld (hl),a pop de ld hl,health call GetCell ld (unit_totalhp),a ld (hl),0 pop de ld hl,power call GetCell ld (unit_totalpower),a ld (hl),0 call action_placeunit_hpandpower ld hl,text_moved jp action_display_result stationaryunitactions: cp 12 \ jr z,setupminelayermenu cp 13 \ jr z,setupmobileyardmenu cp 16 \ jr z,setupcapitalmenu cp 17 \ jr z,setupbootcampmenu cp 18 \ jr z,setupwarfactorymenu cp 19 \ jr z,setupairportmenu ld hl,is_this_a_missilesilo cp 15 \ jr z,setupmissilesilomenu setupresearchlabmenu: ld (hl),0 ;Important for when buying an airstrike or a nuke ld a,4 ld hl,researchlabbuymenu jr setupdrawbuymenu setupmissilesilomenu: ld (hl),1 ld a,2 ld hl,missilesilobuymenu jr setupdrawbuymenu setupminelayermenu: ld a,1 ld hl,minelayerbuymenu jr setupdrawbuymenu setupmobileyardmenu: ld a,6 ;Amount of things for sale ld hl,mobileyardbuymenu jr setupdrawbuymenu setupcapitalmenu: ld a,6 ld hl,capitalbuymenu jr setupdrawbuymenu setupbootcampmenu: ld a,4 ld hl,bootcampbuymenu jr setupdrawbuymenu setupwarfactorymenu: ld a,6 ld hl,factorybuymenu jr setupdrawbuymenu setupairportmenu: ld a,2 ld hl,airportbuymenu setupdrawbuymenu: ld (temp_address_4),a ;Temp_address_4 contains the amount of things for sale ld (temp_address_6),hl ;Temp_address_6 contains the data of the things you can buy ld (buy_menu_address),hl ;Saves it to the buy_menu_address as well (T_A_6 gets screwed up) ld de,$0208 ld hl,leftarrow ld (temp_address_1),de ld (sprite_address),hl call displayunitsprite ld de,$020f ld hl,rightarrow ld (temp_address_1),de ld (sprite_address),hl call displayunitsprite ld de,$0209 ld (temp_address_7),de ld a,(temp_address_4) ld b,a drawbuymenu: push bc ld hl,(temp_address_6) ld a,(hl) call GetSprite ld ix,(sprite_address) ld bc,VideoRam2 ld de,(temp_address_7) call PutSprite ld hl,temp_address_6 \ inc (hl) ;Increments hl to get the next purchasable thing's unit number inc hl \ inc hl \ inc (hl) ;Increments the location to display it at pop bc djnz drawbuymenu buymenucursor: ld a,1 ;a=current value of cursor ld (temp_address_1),a ;Moved into temp_address_1 buymenucursor_newitem: ld a,(temp_address_1) ld hl,(buy_menu_address) dec hl call AddAtoHL ld a,(hl) ;a now contains the value of the thing they want to buy ld (action_unit_value),a call GetUnitName ;NAME DISPLAYING ROUTINE ld a,30 ld d,96 call vputs_center ld hl,text_buymenu ;Text array displaying preparation ld de,$2648 ld b,4 call DisplayTextArray ld de,$cbd9 ;Displays a line beneath the unit's name ld hl,$fdd9 ld b,6 call Horizontal ld de,$cc59 ;Displays a line beneath the unit's name ld hl,$fe59 ld b,6 call Horizontal ld bc,$3871 ;DISPLAYS THE COST ld hl,cost-1 call buyunit_getcostorrange ld (unit_cost),a call displaya ld a,(action_unit_value) cp 21 \ jr nc,buymenucursor_newitem_1 ld bc,$3271 ;DISPLAYS THE RANGE ld hl,baserange-1 call buyunit_getcostorrange ld (unit_range),a call displaya ld bc,$2671 ld de,hp_bonus-1 ;HP DISPLAYING ROUTINE ld hl,basehp-1 call buyunit_gethporpower ld (unit_totalhp),a call displaya ld bc,$2c71 ;POWER DISPLAYING ROUTINE ld de,power_bonus-1 ld hl,basepower-1 call buyunit_gethporpower ld (unit_totalpower),a call displaya buymenucursor_newitem_1: call buymenucursor_invert buymenucursor_movethecursor: call Majorslow ld a,%11111110 ;Set which row to check out (1),a ;Send it in a,(1) ;Get results bit 2,a \ jr z,buymenucursor_right ;[right] bit 1,a \ jr z,buymenucursor_left ;[left] ld a,%10111111 ;Set which row to check out (1),a ;Send it in a,(1) ;Get results bit 5,a \ jr z,buymenucursor_buyunit bit 6,a \ jp z,error_actioncancelled jr buymenucursor_movethecursor buymenucursor_right: ld a,(temp_address_1) ld hl,temp_address_4 cp (hl) \ jr z,buymenucursor_movethecursor push af call buymenucursor_invert pop af inc a jr buymenucursor_common buymenucursor_left: ld a,(temp_address_1) cp 1 \ jr z,buymenucursor_movethecursor push af call buymenucursor_invert pop af dec a buymenucursor_common: ld (temp_address_1),a ld de,$cb88 ld hl,$fd88 ld b,40 call ClearArea jp buymenucursor_newitem buymenucursor_buyunit: ld a,(action_unit_value) push af ld a,(unit_cost) push af ld a,(current_player) ld hl,player_money-1 call AddAtoHL ld a,(hl) ;a now contains the player's cash ld (player_cash_when_buying),a pop bc cp b \ jp c,error_cannotaffordit pop af cp 21 \ jr nc,buyunit_specialitem buyunit_specialitem_mine: call clearlowerstatarea xor a \ ld (display_doable_action),a ld (display_stats),a ;DO NOT SEPARATE THESE THREE LINES inc a \ ld (placing_unit),a buyunit_placeunit: ld hl,(cursor_xy) ;Loads the old cursor value into hl ld b,1 ;Sets the range to 1 to prevent placing units anywhere call SetRanges call cursor_display_place_1 call Cursor cp 255 \ jp z,error_actioncancelled ;Exit cancels the buying ld a,(unit_action) \ and a \ jp z,error_actioncancelled call getoffset ld (temp_address_7),de ;temp_address_1 now contains the offset of the new cursor location ld hl,units call GetCellandUnitValue cp 26 \ jp z,boom and a \ jp nz,error_spottaken ld a,(action_unit_value) ;Places the unit in the correct cell ld (hl),a ld a,(current_player) ;Checks to see which player it is cp 2 \ jr z,buyunit_placeunit_player2unit set 6,(hl) ;Sets the player bit in the unit value buyunit_placeunit_1: call action_placeunit_hpandpower jp buyunit_finish buyunit_placeunit_player2unit: ;part of the buyunit_placeunit routine above set 7,(hl) jr buyunit_placeunit_1 buyunit_specialitem: cp 22 \ jr z,buyunit_specialitem_increasedhp cp 23 \ jr z,buyunit_specialitem_increasedpr cp 24 \ jr z,buyunit_specialitem_airstrike cp 25 \ jr z,buyunit_specialitem_nuke cp 26 \ jr z,buyunit_specialitem_mine buyunit_specialitem_bank: ld hl,player_banks-1 jr buyunit_specialitem_finish buyunit_specialitem_increasedhp: ld hl,hp_bonus-1 jr buyunit_specialitem_finish buyunit_specialitem_increasedpr: ld hl,power_bonus-1 buyunit_specialitem_finish: ld a,(current_player) call AddAtoHL inc (hl) jp buyunit_finish buyunit_specialitem_airstrike: ld hl,airstrike_research-1 ld a,(current_player) call AddAtoHL ld a,(is_this_a_missilesilo) \ and a \ jr z,buyunit_specialitem_research ld a,(hl) \ cp 1 \ jp c,error_research ld a,20 ;20 will be the damage done jr setexplosion buyunit_specialitem_nuke: ld hl,nuke_research-1 ld a,(current_player) call AddAtoHL ld a,(is_this_a_missilesilo) \ and a \ jr z,buyunit_specialitem_research ld a,(hl) \ cp 1 \ jp c,error_research ld a,50 ;50 will be the damage done setexplosion: ld (explosion_damage),a xor a \ ld (display_doable_action),a ld (display_name_only),a ;DO NOT SEPARATE THESE 4 LINES inc a \ ld (display_stats),a ld (firing_projectile),a call cursor_display_projectile_1 call Cursor cp 255 \ jp z,error_actioncancelled ld a,(unit_action) and a \ jp z,error_actioncancelled call getoffset ld (temp_address_7),de ;de now contains the offset of the correct tile call Explosion call clearlowerstatarea ld hl,text_areabombed ld bc,$1141 ld (_penCol),bc call _vputs jr buyunit_finish buyunit_specialitem_research: ld (hl),1 buyunit_finish: ld a,(unit_cost) ld b,a ld a,(player_cash_when_buying) sub b ;Subtracts the cost and saves the player's money back push af ld hl,player_money-1 ;Gets the correct address for the player's cash ld a,(current_player) call AddAtoHL pop af ld (hl),a ld hl,text_purchased jp action_display_result buymenucursor_invert: ld a,(temp_address_1) ld hl,$cb08 call AddAtoHL jp invert error_research: ld hl,text_research jr error_displayactionerror error_actioncancelled: ld hl,text_actioncancelled jr error_displayactionerror error_spottaken: ld hl,text_spottaken jr error_displayactionerror error_cannotaffordit: pop af ;Jumped out while there was still a pushed thing ld hl,text_youcannotaffordit jr error_displayactionerror error_notyours: ld hl,text_itsnotyours jr error_displayactionerror error_nothingthere: ld hl,text_thereisnounitthere jr error_displayactionerror error_notusable: ld hl,text_cannotdoanythingtoit error_displayactionerror: push hl call clearlowerstatarea ld de,$1041 ld b,2 pop hl call DisplayTextArray ld a,1 \ ld (display_stat_sprites_at),a call displaylandsprite jp incompleteaction buyunit_getcostorrange: ld (_penCol),bc ld a,(action_unit_value) call AddAtoHL ld a,(hl) ;a now contains the value ret buyunit_gethporpower: ld (_penCol),bc ld a,(action_unit_value) call AddAtoHL ld a,(hl) ld b,a ex de,hl ld a,(current_player) ;Has to add in the extra bonus that players can buy call AddAtoHL ld a,(hl) add a,b ret action_placeunit_hpandpower: ld hl,health ld de,(temp_address_7) call GetCell ld a,(unit_totalhp) ld (hl),a ld hl,power ld de,(temp_address_7) call GetCell ld a,(unit_totalpower) ld (hl),a ret ;----------------------------------------------------------------------------------------Stats routines Stats: ld a,(display_stats) \ and a \ ret z ld a,(should_stats_be_moved_down) \ cp 1 \ jr z,movestatdatadown ld a,8 \ ld (display_stat_text_at),a ld a,1 \ ld (display_stat_sprites_at),a call clearstatarea jr stats_1 movestatdatadown: ld a,24 \ ld (display_stat_text_at),a ld a,3 \ ld (display_stat_sprites_at),a call clearsecondarystatarea stats_1: call setupstatbar call getoffset ld (temp_address_4),de ld hl,units call GetCell ld (unit_cell_value),a call GetUnitValue ;Gets the value of the sprites push af call GetFlippableSprite call setupstatsprite ld de,(temp_address_4) ld hl,land call GetCell ld (temp_address_2),a pop af and a \ jp z,landstats cp 27 \ jp z,rockstats cp 26 \ jp z,landstats push af call GetUnitName ld a,(display_stat_text_at) ld b,a ld c,$46 ld (_penCol),bc call _vputs call blackensomething ld a,(display_name_only) cp 1 \ jp z,displaynameonly ld bc,$086b call placestattextcursor ld de,(temp_address_4) ld hl,units call GetCell call GetOwnerValue call displaya call displaystatvalues ld bc,$206b call placestattextcursor ld hl,baserange pop af dec a call AddAtoHL ld a,(hl) call displaya ld a,(display_stat_text_at) add a,8 ld d,a ld e,$41 ld b,5 ld hl,text_stats call DisplayTextArray jr displaylandsprite landstats: ld a,(temp_address_2) cp 1 \ jr z,midlandstats cp 2 \ jr z,highlandstats ld hl,lowlanddata displaytextdata: ld a,(display_stat_text_at) ld d,a ld e,$46 ld (_penCol),de push de call _vputs push hl call blackensomething pop hl pop de push hl ld hl,$07FB add hl,de ex de,hl pop hl ld b,1 push af ;Dumped in to compensate for the push at the top ld a,(display_name_only) \ cp 1 \ jr z,displaynameonly pop af call DisplayTextArray displaylandsprite: ld a,(temp_address_2) ld b,a ld de,8 call Multiply ld de,lowlands add hl,de push hl pop ix ld bc,VideoRam ld a,(display_stat_sprites_at) ld d,a ld e,$0f jp PutSprite midlandstats: ld hl,midlanddata jr displaytextdata highlandstats: ld hl,highlanddata jr displaytextdata rockstats: ld hl,rockdata jr displaytextdata displaynameonly: pop af ;Left without being popped call BlackenText jr displaylandsprite getoffset: ld a,(cursor_x) ld b,a ld a,(upper_left_x) add a,b ld d,a ld a,(cursor_y) ld b,a ld a,(upper_left_y) add a,b ld e,a ret placestattextcursor: ld a,(display_stat_text_at) add a,b ld b,a ld (_penCol),bc ret displaystatvalues: ld bc,$146b ld hl,health call displaystatvalue ld bc,$1a6b ld hl,power displaystatvalue: call placestattextcursor ld de,(temp_address_4) call GetCell ld hl,0 ld l,a jp DisplayHL displaystattext: call placestattextcursor jp _vputs ;----------------------------------------------------------------------------------------Cursor routine Cursor: ;Input: (stat_xy)=location for sprite display call Majorslow call Majorslow cursor_1: ld hl,$0aFF \ ld (idle_counter),hl cursor_2: call DrawCursor skiptheinversion: call Slow ld hl,(idle_counter) dec hl xor a \ cp h \ call z,Off ld (idle_counter),hl ld a,(display_doable_action) \ cp 1 \ call z,cursor_display ld a,(placing_unit) \ cp 1 \ call z,cursor_display_place ld a,(firing_projectile) \ cp 1 \ call z,cursor_display_projectile ld a,1 \ ld (cursor_moved),a ld a,%11111110 ;Set which row to check out (1),a ;Send it in a,(1) ;Get results ld hl,(cursor_xy) ;Load hl to be manipulated bit 3,a \ jp z,up ;[up] bit 2,a \ jp z,right ;[right] bit 1,a \ jp z,left ;[left] bit 0,a \ jp z,down ;[down] xor a \ ld (cursor_moved),a skipthearrowcheck: push hl call DrawCursor pop hl skipthecursordrawing: ld (cursor_xy),hl ;Save it back skipthesaving: ld a,%11011111 out (1),a ;Send it in a,(1) ;Get results bit 7,a \ call z,Stats ld a,%11111101 out (1),a in a,(1) bit 1,a \ jr z,contrastup bit 2,a \ jr z,contrastdown ld a,%10111111 ;Set which row to check out (1),a ;Send it in a,(1) ;Get results bit 4,a \ call z,help bit 7,a \ jr z,prepareskipturn bit 5,a \ ret z bit 6,a \ jp nz,cursor_2 ld a,255 ;Exits back to the turn loop ret prepareskipturn: ld a,(allow_turn_skipping) cp 1 \ jp nz,cursor_1 ld a,100 ret contrastup: ld a,31 ld hl,$c008 cp (hl) jp z,cursor_1 inc (hl) jr finishcontrastroutine contrastdown: xor a ld hl,$c008 cp (hl) jp z,cursor_1 dec (hl) finishcontrastroutine: ld a,(hl) out (2),a call Majorslow jp cursor_1 fix_screen: call ClearPage call RedrawScreen call OpenGray jp Cursor up: call getoffset ld a,(upper_range) cp e jp nc,skipthearrowcheck dec l call Majorslow jp nz,skipthearrowcheck inc l ld a,(upper_left_y) and a \ jp z,skipthearrowcheck dec a ld (upper_left_y),a jr fieldscrolled left: call getoffset ld a,(left_range) cp d jp nc,skipthearrowcheck dec h call Majorslow jp nz,skipthearrowcheck inc h ld a,(upper_left_x) and a \ jp z,skipthearrowcheck dec a ld (upper_left_x),a jr fieldscrolled right: call getoffset ld a,(right_range) cp d jp c,skipthearrowcheck inc h ld a,8 cp h call Majorslow jp nc,skipthearrowcheck dec h ld a,(upper_left_x) cp 4 \ jp z,skipthearrowcheck inc a ld (upper_left_x),a jr fieldscrolled down: call getoffset ld a,(lower_range) cp e jp c,skipthearrowcheck inc l ld a,8 cp l call Majorslow jp nc,skipthearrowcheck dec l ld a,(upper_left_y) cp 4 \ jp z,skipthearrowcheck inc a ld (upper_left_y),a fieldscrolled: push hl call DrawField pop hl jp skipthecursordrawing SetRanges: push bc call getoffset pop bc push de push bc push de push bc push de push bc ld a,e upper: sub b cp 13 \ call nc,decreaserangetoolow ld (upper_range),a pop bc pop de ld a,d leftside: sub b cp 13 \ call nc,decreaserangetoolow ld (left_range),a pop bc pop de ld a,e lower: add a,b dec a cp 13 \ call nc,decreaserangetoohigh ld (lower_range),a pop bc pop de ld a,d rightside: add a,b dec a cp 13 \ call nc,decreaserangetoohigh ld (right_range),a ret decreaserangetoolow: xor a ret decreaserangetoohigh: ld a,12 ret cursor_display_place: ld a,(cursor_moved) \ and a \ ret z cursor_display_place_1: ld a,(action_unit_value) \ cp 26 \ jr z,cursor_display_projectile_1 cp 14 \ jr z,cursor_display_projectile_1 call clearlowerstatarea call Stats ld bc,$1141 ld (_penCol),bc ld hl,text_target call _vputs call getoffset ld (temp_address_7),de ld hl,units call GetCellandUnitValue cp 26 \ jp z,cursor_display_place_2 and a \ jp nz,cursor_display_impossible cursor_display_place_2: ld a,1 \ ld (unit_action),a ld hl,text_place jp _vputs cursor_display_projectile: ld a,(cursor_moved) \ and a \ ret z cursor_display_projectile_1: call clearlowerstatarea ld bc,$1141 ld (_penCol),bc ld hl,text_target call _vputs call getoffset ld a,1 cp d \ jp z,cursor_display_impossible cp e \ jp z,cursor_display_impossible ld a,12 cp d \ jp z,cursor_display_impossible cp e \ jp z,cursor_display_impossible ld a,(action_unit_value) \ cp 26 \ jr z,cursor_display_radius cp 14 \ jr z,cursor_display_radius ld a,1 \ ld (unit_action),a ld hl,text_launch jp _vputs cursor_display_radius: call getoffset ld hl,units call GetCellandUnitValue and a \ jp nz,cursor_display_impossible ld a,1 \ ld (unit_action),a ld hl,text_place jp _vputs cursor_display: ld a,(cursor_moved) \ and a \ ret z cursor_display_1: call clearlowerstatarea ld hl,text_target ld bc,$1142 ld (_penCol),bc call _vputs call Stats call getoffset ld (temp_address_7),de ld hl,units call GetCell ld (temp_address_6),a ;temp_address_6 contains the target unit's DATA call GetUnitValue and a \ jp z,cursor_display_move cp 26 \ jp z,cursor_display_moveontomine cp 27 \ jp z,cursor_display_harvest ld a,(temp_address_6) call GetOwnerValue ld hl,current_player cp (hl) \ jp z,cursor_display_sameplayer cursor_display_differentplayer: ld hl,text_attack ld a,2 \ ld (unit_action),a ;2 means to attack jp cursor_display_action cursor_display_sameplayer: ld hl,(temp_address_1) ld de,(temp_address_7) sbc hl,de jp z,cursor_display_sameplayer_shop ld de,(temp_address_1) ld hl,units call GetCellandUnitValue cp 7 \ jr z,setup_engineer cp 8 \ jp nz,cursor_display_impossible setup_medic: ld hl,medicheal jr checkifhealable setup_engineer: ld hl,engineerheal checkifhealable: push hl ld de,(temp_address_7) ld hl,units call GetCellandUnitValue pop hl checkifhealable_check: cp (hl) \ jr z,cursor_display_sameplayer_end inc hl ld (temp_address_2),a xor a cp (hl) \ jp z,cursor_display_impossible ld a,(temp_address_2) jr checkifhealable_check cursor_display_sameplayer_end: ld a,3 \ ld (unit_action),a ;3 means to heal ld hl,text_heal jr cursor_display_action cursor_display_sameplayer_shop: ld hl,units call GetCellandUnitValue cp 12 \ jr c,cursor_display_impossible ld (unit_action),a ld hl,text_shop jr cursor_display_action cursor_display_harvest: ld de,(temp_address_1) ld hl,units call GetCellandUnitValue cp 11 \ jr nz,cursor_display_impossible ld a,4 \ ld (unit_action),a ;4 means to harvest ld hl,text_harvest jr cursor_display_action cursor_display_moveontomine: ld a,6 \ ld (unit_action),a ;6 means there is a hidden mine ld hl,text_move jr cursor_display_action cursor_display_move: ld a,1 \ ld (unit_action),a ;1 means to move ld hl,text_move cursor_display_action: ld bc,$1158 ld (_penCol),bc jp _vputs cursor_display_impossible: xor a \ ld (unit_action),a ;0 means to cancel ld hl,text_cancel jr cursor_display_action #include "gray2.asm" #include "help.asm" #include "routines.asm" #include "drawfield.asm" #INCLUDE "rle.asm" #include "options.asm" #include "data.asm" #include "vatsrch.inc" m_start: ;New game data m_time_left: .db 3 m_current_player: .db 1 m_cursor_xy: .db 2,2 m_upper_left_x: .db 0 m_upper_left_y: .db 0 m_upper_right_x: .db 0 m_upper_right_y: .db 0 m_end: spointer: .dw 0 save_name: .db 6,"tcsave" data_start = $ units = $ land = $+144 health = $+288 power = $+432 player_money = $+576 player_banks = $+578 hp_bonus = $+580 power_bonus = $+582 airstrike_research = $+584 nuke_research = $+586 majordata = $+588 time_left = $+588 current_player = $+589 cursor_xy = $+590 upper_left_x = $+592 upper_left_y = $+593 upper_right_x = $+594 upper_right_y = $+595 data_end = $+596 .end