-
Notifications
You must be signed in to change notification settings - Fork 0
hla.inc
The code in this file both provides the simple conditional if...else...endif and a flexible for of looping bases upon the processor flags.
The 'if' will insert a relative branch instruction based on your chosen condition, branching to the 'else' if it's present, or to the 'endif' otherwise.
The 'else' part of the structure is optional, but if present will insert a JMP instruction to the 'endif'.
The 'endif' must be present.
The opening 'if' statement can be one of the following:
- if_eq
- if_zero
- if_ne
- if_not_zero
- if_plus
- if_minus
- if_c_set
- if_c_clr
- if_v_set
- if_v_clr
- if_lt - if less than
- if_gt - if greater than
- if_le - if less than or equal
- if_ge - if greater than or equal
The opening 'do' statement must be present.
Within the structure, then can be one or more of the 'exit_loop' or 'while' instructions.
The 'exit_loop' is an unconditional statement and will cause the loop to terminate immediately when reached.
The 'while' statement will cause the loop to terminate immediately if the condition it is checking is false.
The 'loop' statement signals the end of the loop structure. If a loop with a condition is used, the statement will loop back to the start of the loop structure if the configution it is checking is true. If a loop without a condition is used, it will JMP to the top of the loop structure.
- while_eq
- while_zero
- while_ne
- while_not_zero
- while_plus
- while_minus
- while_c_set
- while_c_clr
- while_v_set
- while_v_clr
- while_lt - while less than
- while_gt - while greater than
- while_le - while less than or equal
- while_ge - while greater than or equal
- loop
- loop_if_eq
- loop_if_zero
- loop_if_ne
- loop_if_not_zero
- loop_if_plus
- loop_if_minus
- loop_if_c_set
- loop_if_c_clr
- loop_if_v_set
- loop_if_v_clr
- loop_if_lt - loop if less than
- loop_if_gt - loop if greater than
- loop_if_le - loop if less than or equal
- loop_if_ge - loop if greater than or equal
... <operation that sets the zero flag> if_eq jsr do_something endif ...
... do jsr update_game loop
On the C64, this code will loop until raster line 255 ($ff) is reached. Note that although the code itself is less compact than the equivalent plain assembly, the structure makes the code a little more readable.
... lda #$ff do cmp $d012 loop_if_ne ...
When HLA_ARITH_COMPARE is defined, the following 4 new branch opscodes are also included:
- blt - branch if less than
- bgt - branch if greater than
- ble - branch if less than or equal
- bge - branch if greater than or equal
Two additional macros have been exported to allow expansion of the 'if' tests and 'loop' tests:
- add_patch_point(jump, type, subtype)
- terminate_loop(jump)
Examples of both macros in use can be found in the 'hla_controller.inc' include file.
This allows you to insert a branch or JMP statement at the current point in the code. The branch of JMP will be patched by the matching 'endif' or 'loop' statement.
When building an 'if' statement, you should specify a type of "if", and a subtype of "if". If you wish to also include a secondary test, then the type remains "if", but the subtype should be set to "test".
When building a 'while' statement, you should specify a type of "loop" and a subtype of "test". As there are no restrictions on the number of 'while' statements inside a loop, there are no other options.
This allows you to build a new 'loop' type statement that uses the branch or JMP statement you specifiy to return to the top of the loop. It may only be used once for the loop and must be at the end.