?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. ; This example shows one of possible ways to use multiple STRUCT definitions
  2. ; as some kind of C-language-like "union"
  3. ;
  4. ; The "receive_buffer" is single block of memory large enough to accomodate
  5. ; any of the specific "commands"
  6. ;
  7. ; RECEIVE_BUFFER_HEADER struct defines the initial header shared across all "commands"
  8. ; RECEIVE_BUFFER_CMD_READ_REGS, RECEIVE_BUFFER_CMD_CONTINUE, RECEIVE_BUFFER_CMD_PED_TEST
  9. ; then define the specific "commands" with their extended fields
  10. ;
  11. ; finally there is small fake process-like subroutine to show usage of the defined fields
  12.  
  13. ; define the command structures
  14.     STRUCT RECEIVE_BUFFER_HEADER
  15. length              DWORD   0
  16. seq_no              BYTE    0
  17. command             BYTE    0
  18.     ENDS
  19.  
  20.     STRUCT RECEIVE_BUFFER_CMD_READ_REGS, RECEIVE_BUFFER_HEADER
  21. register_number     BYTE    0
  22.     ENDS
  23.  
  24.     STRUCT RECEIVE_BUFFER_CMD_CONTINUE, RECEIVE_BUFFER_HEADER
  25. bp1_enable          BYTE    0
  26. bp1_address         WORD    0
  27. bp2_enable          BYTE    0
  28. bp2_address         WORD    0
  29.     ENDS
  30.  
  31.     STRUCT RECEIVE_BUFFER_CMD_PED_TEST, RECEIVE_BUFFER_HEADER
  32. pattern             BLOCK   256
  33.     ENDS
  34.  
  35. ; find the structure with maximum size to define how long the receive_buffer should be
  36. RB_MAX_SIZE         = RECEIVE_BUFFER_HEADER
  37. RB_MAX_SIZE         = RB_MAX_SIZE >? RECEIVE_BUFFER_CMD_READ_REGS
  38. RB_MAX_SIZE         = RB_MAX_SIZE >? RECEIVE_BUFFER_CMD_CONTINUE
  39. RB_MAX_SIZE         = RB_MAX_SIZE >? RECEIVE_BUFFER_CMD_PED_TEST
  40.  
  41. ; reserve the memory for the receive_buffer (one buffer for all)
  42.     ORG     $8000
  43. receive_buffer      RECEIVE_BUFFER_HEADER
  44. .data               BLOCK   RB_MAX_SIZE - RECEIVE_BUFFER_HEADER, 0
  45.  
  46. ; definie alias labels for "receive_buffer" to access specific-command fields
  47. rb_read_regs    RECEIVE_BUFFER_CMD_READ_REGS = receive_buffer
  48. rb_continue     RECEIVE_BUFFER_CMD_CONTINUE = receive_buffer
  49. rb_ped_test     RECEIVE_BUFFER_CMD_PED_TEST = receive_buffer
  50.  
  51. ; example of usage in code
  52.     ORG     $C000
  53. process_command:
  54.     ld      a,(receive_buffer.command)
  55.     cp      1
  56.     jr      nz,.not_read_regs
  57.     ; CMD_READ_REGS specific code
  58.     ld      a,(rb_read_regs.register_number)
  59.     rst     0
  60. .not_read_regs:
  61.     cp      2
  62.     jr      nz,.not_continue
  63.     ; CMD_CONTINUE specific code
  64.     ld      hl,(rb_continue.bp1_address)
  65.     ld      de,(rb_continue.bp2_address)
  66.     ld      bc,(rb_continue.bp1_enable) ; C = bp1_enable
  67.     ld      a,(rb_continue.bp2_enable)
  68.     ld      b,a                         ; B = bp2_enable
  69.     rst     0
  70. .not_continue:
  71.     ; must be RECEIVE_BUFFER_CMD_PED_TEST then
  72.     ld      hl,rb_ped_test.pattern
  73.     ld      bc,$5B          ; C = ZX Next sprite pattern upload port, B = 0 (256x)
  74.     otir                    ; upload pattern to active pattern slot
  75.     rst     0
  76.