Disk.asm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. include_flags equ 1
  2. include_struc equ 1
  3. include_deb_mac equ 1
  4. include_macros equ 1
  5. include_error_codes equ 1
  6. include_language_codes equ 1
  7. include include.asm
  8. ; The data for game 2 will be held in one very large data file.
  9. ; A small file contains the data required for loading the data
  10. no_of_files_hd equ 1600 ;1500
  11. no_of_files_cd equ 5200
  12. max_files_in_list equ 60 ;max no of files in chip list or fast list
  13. start32data
  14. data_file_name db "sky.dsk",0
  15. dinner_file_name db "sky.dnr",0
  16. restart_name db "sky.rst",0
  17. config_name db "sky.cfg",0
  18. save_game_text_fileh db "sky .sav",0
  19. save_game_nameh db "sky .000",0
  20. ; cfg actual
  21. lang_conv db 0 ;0 English English
  22. db usa_code ;3 Us American
  23. db french_code ;2 French French
  24. db german_code ;1 German German
  25. db iti_code ;5 Italian Italian
  26. db spa_code ;xx6 P'guese P'guese
  27. db por_code ;xx7 Spanish Swedish
  28. db swe_code ;4 Swedish Swedish
  29. align 4
  30. restart_name_p dd 0 ;pointer to name of restart file
  31. save_game_text_file dd 0
  32. save_game_name dd 0
  33. config_file_present dd 0
  34. data_disk_handle dd ? ;handle for data disk
  35. ;dinner_table dd (no_of_files*2) dup (0)
  36. dinner_table_area dd ? ;where to put the dinner table
  37. dinner_table_size dd ? ;no of files we are allowed
  38. file_flags dd ? ;flags from dinner table
  39. file_offset dd ? ;offset into dsk file
  40. file_size dd ? ;size of file
  41. fixed_dest dd ? ;set to 0 if we don't have a fixed place
  42. file_dest dd ? ;where to load the data
  43. comp_dest dd ? ;where to decompress it to
  44. decomp_size dd ? ;uncompressed size
  45. ifdef debug_42
  46. comp_file dd ?
  47. endif
  48. build_list dw max_files_in_list dup (0) ;list of loaded files
  49. end32data
  50. start32save_data
  51. ; fast and chip list not allocated so it can be saved easily
  52. loaded_file_list dd max_files_in_list dup (0) ;list of loaded files
  53. end32save_data
  54. start32code
  55. extrn my_malloc:near
  56. extrn my_free:near
  57. extrn _UnpackM1:near
  58. initialise_disk proc
  59. ; Load in the dinner table
  60. mov eax,no_of_files_hd*8 ;allocate space for dinner table
  61. mov ebx,no_of_files_hd
  62. test [_cd_version],-1 ;cd version has far more
  63. je not_id_cd
  64. mov eax,no_of_files_cd*8 ;allocate space for dinner table
  65. mov ebx,no_of_files_cd
  66. not_id_cd: mov [dinner_table_size],ebx
  67. call my_malloc
  68. mov [dinner_table_area],eax
  69. open_file dinner_file_name,em_no_dnr_file
  70. mov [restart_name_p],offset restart_name
  71. mov [save_game_text_file],offset save_game_text_fileh
  72. mov [save_game_name],offset save_game_nameh
  73. mov edx,offset data_disk_handle ;check no of files is correct
  74. mov ecx,4
  75. mov ebx,eax
  76. mov ah,3fh
  77. disk_int
  78. jc dnr_f_error
  79. mov eax,[data_disk_handle] ;no of files in dnr
  80. cmp [dinner_table_size],eax
  81. jnc disk_ok
  82. disk_rd_error2:: program_error em_disk_rd_error
  83. dnr_f_error: program_error em_dnr_file
  84. disk_ok: ;Load in the dinner table
  85. mov [dinner_table_size],eax
  86. mov edx,[dinner_table_area]
  87. shl [data_disk_handle],3 ;8 bytes per entry
  88. mov ecx,[data_disk_handle]
  89. mov ah,3fh
  90. disk_int
  91. jc disk_rd_error2
  92. cmp eax,[data_disk_handle]
  93. jne disk_rd_error2
  94. close_file
  95. ; Open up the data disk
  96. open_file data_file_name,em_no_dsk_file
  97. mov [data_disk_handle],eax
  98. ret
  99. initialise_disk endp
  100. load_fixed_items proc
  101. ; Load in one or two files
  102. ifndef s1_demo
  103. load_fixed 36
  104. endif
  105. load_fixed 49
  106. load_fixed 50
  107. load_fixed 73
  108. load_fixed 262
  109. ifndef s1_demo
  110. load_fixed 263
  111. load_fixed 264
  112. load_fixed 265
  113. load_fixed 266
  114. load_fixed 267
  115. load_fixed 269
  116. load_fixed 271
  117. load_fixed 272
  118. endif
  119. ret
  120. load_fixed_items endp
  121. ifdef mem_check
  122. free_fixed_items proc
  123. free_fixed_item 36
  124. free_fixed_item 49
  125. free_fixed_item 50
  126. free_fixed_item 73
  127. free_fixed_item 262
  128. free_fixed_item 263
  129. free_fixed_item 264
  130. free_fixed_item 265
  131. free_fixed_item 266
  132. free_fixed_item 267
  133. free_fixed_item 269
  134. free_fixed_item 271
  135. free_fixed_item 272
  136. ret
  137. free_fixed_items endp
  138. endif
  139. ;--------------------------------------------------------------------------------------------------
  140. load_file proc
  141. ; Load in file eax to address edx.
  142. ; If edx = 0 then allocate memory for this file
  143. ; First find the file
  144. ifdef file_order_chk
  145. extrn _this_file_loaded__Ni:near
  146. push_all
  147. push eax
  148. call _this_file_loaded__Ni
  149. pop_all
  150. endif
  151. ifdef debug_42
  152. ;call_address
  153. mov [comp_file],eax
  154. show_files "load file %d,%d (%d)"
  155. test [_cd_version],-1
  156. je njnj
  157. border 3fh
  158. njnj:
  159. endif
  160. ifdef with_screen_saver
  161. mov [sssss_count],0 ;loading files is a sign of activity
  162. endif
  163. call get_file_info
  164. mov eax,[esi+5] ;get size + flags
  165. mov [file_flags],eax
  166. and eax,03fffffh
  167. mov [file_size],eax
  168. ;printf "size %d",eax
  169. ifdef debug_42
  170. jifne eax,f_not_miss
  171. ret
  172. f_not_miss:
  173. endif
  174. mov ecx,[esi+2] ;get file offset
  175. and ecx,0ffffffh
  176. ;printf "offset 1 %d (%x)",ecx,ecx
  177. btr ecx,23
  178. jnc no_xtra
  179. shl ecx,4 ;position goes over 16m boundary
  180. no_xtra: mov [file_offset],ecx
  181. mov [fixed_dest],edx ;save dest address or 0 if we need some
  182. mov [file_dest],edx
  183. mov [comp_dest],edx
  184. ; Do we need to allocate memory
  185. or edx,edx
  186. jne no_allocate
  187. call my_malloc
  188. mov [file_dest],eax
  189. no_allocate: ;Position the file pointer
  190. mov ax,4200h
  191. mov ebx,[data_disk_handle]
  192. mov ecx,[file_offset]
  193. ;printf "offset 2 %d (%x)",ecx,ecx
  194. ifdef file_order_chk
  195. extrn _position_file__Ni:near
  196. push_all
  197. push ecx
  198. call _position_file__Ni
  199. pop_all
  200. endif
  201. mov edx,ecx
  202. shr ecx,16
  203. and edx,0ffffh
  204. bts [system_flags],sf_test_disk
  205. disk_int
  206. jc disk_rd_error2
  207. btr [system_flags],sf_test_disk
  208. shl edx,16 ;check we got there
  209. mov dx,ax
  210. cmp edx,[file_offset]
  211. jne disk_rd_error2
  212. ; Now read in the data
  213. mov ah,3fh
  214. mov ebx,[data_disk_handle]
  215. mov ecx,[file_size]
  216. ;printf "size %d",ecx
  217. ifdef file_order_chk
  218. extrn _load_file_data__Ni:near
  219. push_all
  220. push ecx
  221. call _load_file_data__Ni
  222. pop_all
  223. endif
  224. mov edx,[file_dest]
  225. bts [system_flags],sf_test_disk
  226. disk_int
  227. btr [system_flags],sf_test_disk
  228. cmp eax,[file_size]
  229. jne disk_rd_error2
  230. mov eax,[file_dest]
  231. bt [file_flags],23 ;skip decomp check?
  232. jc not_compressed
  233. ;--------------------------------------------------------------------------------------------------
  234. ; check for old robby boy
  235. bt (s ptr[eax]).flag,7 ;bit 7 set for robs compression
  236. jnc not_robbo
  237. ; decompress northern style
  238. mov esi,eax
  239. movzx eax,(s ptr[esi]).flag ;get uncompressed size
  240. clear al
  241. shl eax,8
  242. mov ax,(s ptr[esi]).s_tot_size
  243. mov [decomp_size],eax ;save total size
  244. ; If we didn't have a place for this file make one
  245. test [fixed_dest],-1
  246. jne got_mem
  247. call my_malloc
  248. mov [comp_dest],eax
  249. got_mem: mov esi,[file_dest]
  250. mov edi,[comp_dest]
  251. bt [file_flags],22 ;do we include the header
  252. jc not_ihead
  253. mov ecx,SIZE s
  254. rep movsb
  255. jmp dun_hed
  256. not_ihead: add esi,SIZE s
  257. dun_hed: push 0
  258. push edi
  259. push esi
  260. call _UnpackM1
  261. lea esp,12[esp]
  262. push ds ;restore es
  263. pop es
  264. ; If eax = 0 then the file was not compressed, we already have it
  265. jifne eax,was_compressed
  266. test [fixed_dest],-1 ;don't free compressed data if dest is fixed
  267. jne fxd_free
  268. mov eax,[comp_dest]
  269. call my_free
  270. fxd_free: mov eax,[file_dest] ;wasn't decompressed so wasn't moved
  271. jmp not_compressed
  272. was_compressed: ;In theory data are now decompressed
  273. bt [file_flags],22 ;did we include the header
  274. jc not_inc_head
  275. add eax,SIZE s
  276. not_inc_head:
  277. ifdef debug_42
  278. cmp eax,[decomp_size] ;check size
  279. je size_ok
  280. printf "********************************"
  281. show_files "decomp file %d,%d (%d)",[comp_file]
  282. printf "decomp size %d",eax
  283. printf "should be %d",[decomp_size]
  284. printf "file flags %x",[file_flags]
  285. printf "file size %d",[file_size]
  286. printf "file offset %d",[file_offset]
  287. printf "********************************"
  288. size_ok:
  289. endif
  290. test [fixed_dest],-1 ;do we need to deallocate file memory
  291. jne no_ffree
  292. mov eax,[file_dest]
  293. call my_free
  294. no_ffree: mov eax,[comp_dest]
  295. jmp not_compressed
  296. not_robbo:
  297. not_compressed:
  298. ifdef debug_42
  299. test [_cd_version],-1
  300. je popo
  301. border 0
  302. popo:
  303. endif
  304. bt [system_flags],sf_mouse_stopped
  305. jnc no_mouse_fix
  306. push eax
  307. call restore_mouse_data
  308. call draw_new_mouse
  309. pop eax
  310. btr [system_flags],sf_mouse_stopped
  311. no_mouse_fix: ;printf "loaded to %x",eax
  312. ret
  313. load_file endp
  314. fn_cache_chip proc
  315. ; chip list always loaded after fast list
  316. fetch_compact ;get address of list
  317. mov edi,offset build_list ;find end of build list
  318. clear eax
  319. mov ecx,-1
  320. repne scasw
  321. lea edi,[edi-2]
  322. build_loop: lodsw
  323. stosw
  324. jifne ax,build_loop
  325. jmp fn_cache_files
  326. fn_cache_chip endp
  327. fn_cache_fast proc
  328. ; fast list always loaded first
  329. ifdef file_order_chk
  330. extrn _lseek_allowed__Ni:near ;disk jump allowed on room change
  331. push_all
  332. push [screen]
  333. call _lseek_allowed__Ni
  334. pop_all
  335. endif
  336. ; if list = 0 then load no files
  337. jife eax,no_files
  338. cherror [build_list],ne,0,em_internal_error
  339. fetch_compact
  340. jife esi,no_files
  341. mov edi,offset build_list
  342. clear eax
  343. build_loop: lodsw
  344. stosw
  345. jifne ax,build_loop
  346. no_files: mov al,1
  347. ret
  348. fn_cache_fast endp
  349. fn_cache_files proc
  350. ; Cache in sprites.
  351. ; Use build list
  352. call trash_all_fx ;get rid of any fx that are going on
  353. mov esi,offset build_list
  354. mov edi,offset loaded_file_list
  355. ; edi points to list of files already loaded
  356. ; esi points to files we want to load
  357. ; First check what files must be kept.
  358. push edi
  359. mov ebx,edi ;use this to update list
  360. one_checked: mov edx,[ebx] ;get a loaded file
  361. jife edx,all_checked
  362. add ebx,4
  363. push esi
  364. check_dump_loop: and wpt[esi],7fffh ;Tony has a dodgy bit 15, trash it and use result
  365. je dump_it ;to check for end of list
  366. cmp dx,[esi] ;check file
  367. je keep_it
  368. add esi,2
  369. jmp check_dump_loop
  370. keep_it: mov [edi],edx ;keep this one
  371. add edi,4
  372. pop esi
  373. jmp one_checked
  374. dump_it: push edi
  375. push ebx
  376. clear eax
  377. and edx,2047 ;strip off disk sets
  378. xchg eax,[offset item_list+edx*4] ;get address and clear entry
  379. call my_free
  380. pop ebx
  381. pop edi
  382. pop esi
  383. jmp one_checked
  384. all_checked: ;esi still points to files we want
  385. ;edi points to end of list
  386. mov dpt[edi],0
  387. pop edi ;now points to start of loaded files
  388. cache_loop: movzx eax,wpt[esi] ;get a file we want
  389. and ax,7fffh ;strip bit and check for end
  390. je cached
  391. lea esi,2[esi]
  392. mov bx,ax ;check for amiga dummy file
  393. and bx,7ffh
  394. cmp bx,7ffh ;7ff is dummy amiga only file
  395. je cache_loop
  396. push edi ;see if we have this file already
  397. check_load_loop: test dpt[edi],-1 ;end of list?
  398. je load_it
  399. cmp eax,[edi]
  400. je skip_it
  401. lea edi,4[edi]
  402. jmp check_load_loop
  403. load_it: ;we need this file
  404. stosd ;put number into list
  405. mov dpt[edi],0
  406. ifdef file_order_chk ;flag cached files as we already check for repeats
  407. extrn _next_file_repeatable__Nv:near
  408. push_all
  409. call _next_file_repeatable__Nv
  410. pop_all
  411. endif
  412. push esi
  413. push eax ;save number for set
  414. clear edx
  415. call load_file ;get the file
  416. pop ebx ;get no for set
  417. and ebx,2047 ;strip disk number
  418. mov [offset item_list+ebx*4],eax ;and put location in
  419. pop esi ;go back for more
  420. skip_it: pop edi
  421. jmp cache_loop
  422. cached: mov [build_list],0
  423. mov al,1
  424. ret
  425. fn_cache_files endp
  426. fn_flush_buffers proc
  427. ; dump all loaded sprites
  428. mov esi,offset loaded_file_list
  429. ; esi points to list to dump
  430. push esi
  431. one_checked: lodsd ;get a loaded file
  432. jife eax,all_checked
  433. push esi
  434. clear edx
  435. and eax,2047 ;strip off disk sets
  436. xchg edx,[offset item_list+eax*4] ;get address and clear entry
  437. mov eax,edx
  438. call my_free
  439. pop esi
  440. jmp one_checked
  441. all_checked: pop esi ;empty list
  442. mov dpt[esi],0
  443. mov al,1
  444. ret
  445. ret
  446. fn_flush_buffers endp
  447. proc_start _load_config__Nv
  448. ; Try and open the config file
  449. ; mov ax,3d00h
  450. ; mov edx,offset config_name
  451. ; disk_int
  452. ; jc no_config
  453. push offset config_name
  454. call _open_for_read__Npc
  455. cmp eax,-1
  456. je no_config
  457. mov [config_file_present],1
  458. ; Load in the config bytes
  459. mov edx,offset config_name ;dont need this again
  460. mov ecx,5
  461. mov ebx,eax
  462. mov ah,3fh
  463. disk_int
  464. movzx eax,[config_name] ;get language byte
  465. mov al,byte ptr [offset lang_conv + eax]
  466. ifdef italian_set
  467. mov al,iti_code
  468. endif
  469. ifdef spanish_set
  470. mov al,spanish_code
  471. endif
  472. mov byte ptr [_language],al
  473. jife al,no_config ;on non english versions have text as well as speech
  474. cmp al,usa_code
  475. je no_config
  476. printf "setting the options!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  477. bts [system_flags],sf_allow_text
  478. bts [system_flags],sf_allow_speech
  479. no_config:
  480. proc_end _load_config__Nv
  481. fn_flush_chip proc
  482. ; This should be done automatically
  483. mov al,1
  484. ret
  485. fn_flush_chip endp
  486. fn_mini_load proc
  487. ; Load in a 'temporary' file
  488. ; load it into the chip list
  489. ; eax is file number
  490. mov esi,offset loaded_file_list ;check file is not already loaded
  491. cherror dpt[esi],e,0,em_internal_error ;always used when other grafix present
  492. look_loop: cmp eax,[esi]
  493. je loaded
  494. lea esi,4[esi]
  495. test dpt [esi],-1
  496. jne look_loop
  497. ; need to load the file
  498. mov [esi],eax ;tag file on to end of list
  499. mov dpt 4[esi],0
  500. push eax
  501. clear edx
  502. call load_file
  503. pop ebx ;make pointer to entry in item list
  504. and ebx,2047
  505. mov [offset item_list+ebx*4],eax
  506. loaded: mov al,1
  507. ret
  508. fn_mini_load endp
  509. get_file_info proc
  510. ; Point to info on file eax
  511. mov esi,[dinner_table_area]
  512. mov ecx,[dinner_table_size]
  513. find_loop: cmp ax,[esi]
  514. je found_file
  515. add esi,8
  516. floop find_loop
  517. ; if file is speech file then return eax=0 if file not found
  518. bt [system_flags],sf_speech_file
  519. jnc not_speech
  520. btr [system_flags],sf_test_disk
  521. pop eax ;trash return address
  522. clear eax
  523. ret ;return with eax = 0
  524. not_speech: show_files "mutating %d,%d (%d)"
  525. cherror eax,e,75,em_internal_error
  526. ifdef debug_42
  527. pop eax ;get to original call address
  528. call_address
  529. push eax
  530. endif
  531. mov eax,75
  532. jmp get_file_info
  533. found_file: ret
  534. get_file_info endp
  535. get_file_size proc
  536. call get_file_info
  537. mov eax,[esi+5] ;get size + flags
  538. and eax,03fffffh
  539. ret
  540. get_file_size endp
  541. restore_file_lists proc
  542. mov esi,offset loaded_file_list
  543. ; Load list of files starting at esi
  544. load_loop: lodsd
  545. jife eax,load_done
  546. push esi
  547. push eax
  548. clear edx
  549. call load_file
  550. pop edx
  551. and edx,2047
  552. mov [offset item_list+edx*4],eax
  553. pop esi
  554. jmp load_loop
  555. load_done: ret
  556. restore_file_lists endp
  557. proc_start _get_current_disk_drive__Nv
  558. mov ah,19h
  559. int 21h
  560. and eax,0ffh
  561. proc_end _get_current_disk_drive__Nv
  562. proc_start _get_free_disk_space__Ni
  563. drive equ 8
  564. mov ah,36h ;get free disk space
  565. mov edx,drive[ebp]
  566. inc edx
  567. int 21h
  568. cmp ax,-1 ;no drive?
  569. je disk_0
  570. movzx eax,ax
  571. movzx ebx,bx
  572. movzx ecx,cx
  573. imul eax,ebx
  574. imul eax,ecx
  575. jmp got_sp
  576. disk_0: clear eax
  577. got_sp:
  578. proc_end _get_free_disk_space__Ni,4
  579. end32code
  580. end
  581.